2014-03-13 81 views
1

在Xcode中5.1我创建了一个非常简单的单一视图的iPhone应用程序,并把the source code at GitHub简单的测试应用 - 与设备旋转和缩放问题

app screenshot

我有禁用自动布局,并把对方的意见如下:scrollView -> contentView -> imageView(这里fullscreen):

Xcode screenshot

contentViewimageView我已禁用自动调整并将其帧设置为{0, 0, 1000, 1000} - 既在故事板中也在viewDidLoad方法中。

我已经启用了双击和捏手势进行缩放。

对于双击,图像以100%或50%的宽度放大。

这工作一开始,但是设备旋转后它打破:

变焦不能正常工作和图像偏移 - 你不能滚动到其左上角:

image screenshot

这是我在​​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)试过了,但找不到任何有用的东西对我来说:

Reveal app

+0

rollview? – Amandir

+0

因为这是我为StackOverflow编写的简化测试用例。在真实的应用程序中,会有更多的东西放在'contentView'上 - 标签和可拖动的字母图块:https://raw.github.com/afarber/ios-newbie/master/DragScroll/screenshot.png –

回答

1

我的源代码似乎是好的,但在接口生成器,我不得不禁用“自动调整子视图”为scrollView:你为什么要使用内容查看,也不要直接添加的ImageView到SC

Xcode screenshot