我的所有应用程序都处于纵向模式,但我有一个横向模式的视图控制器作为图像库。
在“项目摘要”选项卡上启用 LandscapeLeft 模式,因此我必须在视图控制器的其余部分中以这种方式禁用旋转,但图像库的 VC 中除外。
我想保持旋转为纵向模式,为此并阻止所有 VC 纵向,我使用了以下代码
-(BOOL)shouldAutorotate{
return YES;
}
-(NSInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
}
return UIInterfaceOrientationPortrait;
}
这让我在之前的 VC 中保持横向模式,而它应该旋转为纵向。
有什么想法吗?
对于人像模式 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;
}
如果您使用的是navigationController,
创建一个这样的类别,
@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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)