Appdelegate里添加方法,覆盖plist效果
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskAll;//4个方向
}
presentViewControllerh方式
//在需要控制的viewController里边填写
单个控制的视图必须以presentViewController方式打开,才会生效
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;//横屏(home键再左或右)
return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown; //竖屏(home键再上或下)
return UIInterfaceOrientationMaskPortrait;//home键再下
return UIInterfaceOrientationMaskPortraitUpsideDown;//home键再上
return UIInterfaceOrientationMaskLandscapeLeft;//home键再左
return UIInterfaceOrientationMaskLandscapeRight;//home键再右
}
//push方式
//添加UINavigationController类别(声明,实现以下方法)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate {
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations{
return self.topViewController.supportedInterfaceOrientations;
}
//在需要控制的viewController里边填写
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (BOOL)shouldAutorotate{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
//页面初次显示可能会显示上一视图控制器方向//设置默认方向(手动设置方向)
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
if([[UIDevice currentDevice]respondsToSelector:@selector(setOrientation:)]) {
BOOL (*objc_msgSendTyped)(id self, SEL _cmd, int animated) = (void*)objc_msgSend;
objc_msgSendTyped([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeRight);
}
}