对于纵向模式 VC,
#pragma mark iOS 5 Orientation Support
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
#pragma mark iOS 6 Orientation Support
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
对于横向模式 VC,
#pragma mark - iOS 5.0 and up Rotation Methods
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationMaskLandscape;
}
#pragma mark - iOS 6.0 and up Rotation Methods
- (NSUInteger)supportedInterfaceOrientations;
{
return UIInterfaceOrientationMaskLandscape;
}
如果您使用的是导航控制器,
像这样创建一个类别,
@interface UINavigationController (Rotation_IOS6)
@end
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
if([self.visibleViewController isMemberOfClass:NSClassFromString(@"YourLandscapeViewController")])
{
return UIInterfaceOrientationMaskLandscape
}
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return [[self topViewController] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if([self.visibleViewController isMemberOfClass:NSClassFromString(@"YourLandscapeViewController")])
{
return UIInterfaceOrientationMaskLandscape
}
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end