我有一些viewControllers
,它们由UINavigationController
(push和pop)管理。我想把不同的viewControllers
限制在不同的orientations
上,比如第一个应该只在Portrait
中,第二个在portrait
中,第三个在landscape
中,第四个可以是portrait
和landscape
。我在ViewController
上设置了一个来自storyBoard
的isInitialViewController
,
- (BOOL) shouldAutorotate{
return NO;
}
没有任何问题,但是当我将navigation controller
(通过push和pop管理这四个视图)设置为来自storyBoard
的isInitialViewController
时,这个函数不再被调用,现在是autoratates
。如何阻止使用此autorotating
作为isInitialViewController
的这些视图。我使用以下函数取决于它是哪个ViewController
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation == UIDeviceOrientationPortrait);//choose portrait or landscape}
- (BOOL) shouldAutorotate{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
//return UIInterfaceOrientationMaskLandscape;
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
// return UIInterfaceOrientationLandscapeLeft |
// UIInterfaceOrientationLandscapeRight;
return UIInterfaceOrientationPortrait;
}
发布于 2015-06-15 12:59:43
只需子类UINavigationController和重写适当的方法:
.h文件:
@interface CustomUINavigationController : UINavigationController
@property BOOL canRotate;
@end
.m文件:
@implementation CustomUINavigationController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate
{
return self.canRotate;
}
@end
发布于 2015-06-15 12:25:41
如果你为UINavigation控制器设定目标C类并覆盖接口定位方法.我认为你试图控制自动旋转。
目标C类http://rypress.com/tutorials/objective-c/categories
https://stackoverflow.com/questions/30844898
复制相似问题