1
在Xcode中5.1我创建了一个非常简单的单一视图的iPhone应用程序,并把the source code at GitHub:简单的测试应用 - 与设备旋转和缩放问题
我有禁用自动布局,并把对方的意见如下:scrollView -> contentView -> imageView
(这里fullscreen):
为contentView
和imageView
我已禁用自动调整并将其帧设置为{0, 0, 1000, 1000}
- 既在故事板中也在viewDidLoad方法中。
我已经启用了双击和捏手势进行缩放。
对于双击,图像以100%或50%的宽度放大。
这工作一开始,但是设备旋转后它打破:
变焦不能正常工作和图像偏移 - 你不能滚动到其左上角:
这是我在3210很短的代码,请指教如何解决它:
- (void)viewDidLoad
{
[super viewDidLoad];
_imageView.frame = CGRectMake(0, 0, 1000, 1000);
_contentView.frame = CGRectMake(0, 0, 1000, 1000);
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
float scale = _scrollView.frame.size.width/1000;
_scrollView.minimumZoomScale = scale;
_scrollView.maximumZoomScale = 2 * scale;
_scrollView.zoomScale = 2 * scale;
_scrollView.contentSize = CGSizeMake(1000, 1000);
}
- (UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView
{
return _contentView;
}
- (IBAction)scrollViewDoubleTapped:(UITapGestureRecognizer*)sender
{
if (_scrollView.zoomScale < _scrollView.maximumZoomScale)
[_scrollView setZoomScale:_scrollView.maximumZoomScale animated:YES];
else
[_scrollView setZoomScale:_scrollView.minimumZoomScale animated:YES];
}
更新:我使用显示的应用程序(这里fullscreen)试过了,但找不到任何有用的东西对我来说:
rollview? – Amandir
因为这是我为StackOverflow编写的简化测试用例。在真实的应用程序中,会有更多的东西放在'contentView'上 - 标签和可拖动的字母图块:https://raw.github.com/afarber/ios-newbie/master/DragScroll/screenshot.png –