滚动视图锁纵向ios6

时间:2012-11-01 09:19:20

标签: uiscrollview ios6 orientation uiinterfaceorientation device-orientation

我必须以方向而不是横向锁定滚动视图。

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        scrollview.scrollEnabled=YES;
        NSLog(@"inside the landscape rotation");
    }
    else
    {
        scrollview.scrollEnabled=NO;
        NSLog(@"inside the portrait rotation");
    }
}

上面的方法工作正常,但是我必须将设备旋转一次 - 有没有办法在不改变方向的情况下锁定potrait中的scrollview?

提前致谢。

1 个答案:

答案 0 :(得分:0)

您可以将锁定代码放在viewDidLayoutSubviews中,如下所示:

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];

    if(UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
    {
        scrollview.scrollEnabled = YES;
        NSLog(@"inside the landscape roatation");
    }
    else
    {
        scrollview.scrollEnabled = NO;
        NSLog(@"inside the portrait roatation");
    }
}