如果需要大部分界面只支持豎屏,部分頁面支持橫屏,需要這樣寫:
如果這幾個方法不起作用,那么估計是你的viewcontroller加在了nav中或tab中,再或者加入nav然后nav加入了tab,那么就要重寫nav或tab的這三個方法:
tab中:
- (BOOL)shouldAutorotate{
return [[self.viewControllers objectAtIndex:(int)self.selectedIndex] shouldAutorotate];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
return [[self.viewControllers objectAtIndex:(int)self.selectedIndex] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return [[self.viewControllers objectAtIndex:(int)self.selectedIndex] preferredInterfaceOrientationForPresentation];
}
nav中:
- (BOOL)shouldAutorotate{
return [self.viewControllers.lastObject shouldAutorotate];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
return [self.viewControllers.lastObject supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];
}
最后在需要橫屏或豎屏的controller中再重寫以上三個方法。