我必须以方向而不是横向锁定滚动视图。
- (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?
提前致谢。
答案 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");
}
}