如果我的应用程序最初支持两种方向,如何在 iOS 7
中强制使用纵向方向?
如果我的应用程序最初支持两种方向,如何在 iOS 7
中强制使用纵向方向?
要对整个应用程序进行设置,请打开项目文件,转到“常规”选项卡,更改设置:
或直接在 Info.plist 文件中更改:
如果您只想在特定的视图控制器上进行设置,请重写 supportedInterfaceOrientations
:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
您可以在官方的UIViewController文档中了解更多有关第二种方法的内容。也许,您会发现更适合您特定问题的方法。
UIViewController *c = [[UIViewController alloc]init];
[self presentViewController:c animated:NO completion:nil];
[self dismissViewControllerAnimated:NO completion:nil];
@interface PlayWithWSWithLibAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
BOOL flagOrientationAll;
}
@property (assign) BOOL flagOrientationAll;
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
//NSLog(@"PlayWithWSWithLibAppDelegate -- supportedInterfaceOrientationsForWindow");
if(flagOrientationAll == YES){
return UIInterfaceOrientationMaskPortrait;
} else {
return UIInterfaceOrientationMaskAll;
}
}
-(void)viewWillAppear:(BOOL)animated
{
self.tabBarController.delegate = self;
PlayWithWSWithLibAppDelegate *delegate = (PlayWithWSWithLibAppDelegate *) [[UIApplication sharedApplication] delegate];
delegate.flagOrientationAll = YES;
}
}
-(void)viewWillDisappear:(BOOL)animated
{
//NSLog(@"viewWillDisappear -- Start");
PlayWithWSWithLibAppDelegate *delegate = (PlayWithWSWithLibAppDelegate *)[[UIApplication sharedApplication] delegate];
delegate.flagOrientationAll = NO;
}
这是我的线程,与你的问题有些相似:iOS 7界面方向
#import <objc/message.h>
objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeRight);//here you may change your desired Orientation