我想为少数视图控制器禁用iOS设备的自动旋转。就像我有一些控制器我希望它只在纵向模式下显示。其他人在横向模式下查看控制器。我使用了以下代码但这些委托方法永远不会被调用?
#pragma mark Orientation handling
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait);
}
答案 0 :(得分:2)
我使用以下方法强制设置纵向方向仅适用于某些选定的视图及其对我的工作,可能会对你有所帮助
1,创建一个全局标记
在AppDelegate方法中创建全局标志所以您可以在任何View控制器中访问它。
在AppDelegate.h中
@property (assign) BOOL flagOrientationAll;
在你的AppDelegate.m
中@synthesize flagOrientationAll;
在AppDelegate.m中添加以下方法
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if(flagOrientationAll == YES){
return UIInterfaceOrientationMaskAll; // All orientation support
} else {
return UIInterfaceOrientationMaskPortrait; // Set only one orientation you want
}
}
2,在ViewController .m中添加以下代码,以便限制旋转
// set flag "flagOrientationAll" to rotate only one view in your particular view
#import AppDelegate.h
-(void)viewWillAppear:(BOOL)animated
{
NSLog (@"webViewController -- viewWillAppear");
[super viewWillAppear:animated];
AppDelegate *delegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
delegate.flagOrientationAll = YES;
}
-(void)viewWillDisappear:(BOOL)animated
{
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
delegate.flagOrientationAll = NO;
}
这是我的帖子:How to set one of the screens in landscape mode in iphone?
如果您有任何问题请告诉我!!