1

我必須鎖定方向而不是橫向的滾動視圖。縱向方向的滾動視圖鎖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中的scrollview而不改變方向?

在此先感謝。

回答

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"); 
    } 
}