scrollview lock in portrait orientation ios6



我必须锁定卷轴的方向而不是在景观中。

- (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中而不会更改方向?

预先感谢。

您可以将锁定代码放在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");
    }
}

最新更新