1

我必须将滚动视图锁定为纵向而不是横向。

- (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 中?

提前致谢。

4

1 回答 1

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");
    }
}
于 2012-11-02T16:56:18.683 回答