如果两个方向最初支持我的应用程序,如何在iOS 7
中强制纵向方向?
答案 0 :(得分:6)
对于整个应用程序,打开项目文件,转到“常规”选项卡,更改设置:
或直接在Info.plist文件中:
如果您只想在特定的视图控制器上使用它,请覆盖supportedInterfaceOrientations
:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
您可以在官方UIViewController documentation了解有关第二种方法的更多信息。也许,您会找到更适合您具体问题的方法。
答案 1 :(得分:2)
UIViewController *c = [[UIViewController alloc]init];
[self presentViewController:c animated:NO completion:nil];
[self dismissViewControllerAnimated:NO completion:nil];
答案 2 :(得分:0)
使用以下方法: 在您的app delegate .h
中@interface PlayWithWSWithLibAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
BOOL flagOrientationAll;
}
@property (assign) BOOL flagOrientationAll;
在您的app delegate .m文件中添加以下方法
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
//NSLog(@"PlayWithWSWithLibAppDelegate -- supportedInterfaceOrientationsForWindow");
if(flagOrientationAll == YES){
return UIInterfaceOrientationMaskPortrait;
} else {
return UIInterfaceOrientationMaskAll;
}
}
在视图中实现以下方式,您希望在iPhone设备中以纵向和横向旋转
-(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 Interface Orientation
答案 3 :(得分:-2)
#import <objc/message.h>
objc_msgSend([UIDevice currentDevice], @selector(setOrientation:), UIInterfaceOrientationLandscapeRight);//here you may change your desired Orientation