上一篇文章是写我实现横竖屏之后遇到的问题,这里说一下是怎么实现横竖屏的
首先,因为我做的是其他页面禁止横屏,只要一个页面横屏,那么第一步,需要在AppDelegate中设置只能竖屏 然后在指定界面开启横屏.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.spOrientation = UIInterfaceOrientationMaskPortrait;
return YES;
}
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return self.spOrientation;
}
下面是指定页面开启横屏
-(void)viewWillAppear:(BOOL)animated{
AppDelegate * delegate = [UIApplication sharedApplication].delegate;
delegate.spOrientation = UIInterfaceOrientationMaskAll;
}
-(void)viewWillDisappear:(BOOL)animated{
AppDelegate * delegate = [UIApplication sharedApplication].delegate;
delegate.spOrientation = UIInterfaceOrientationMaskPortrait;
}
因为前一个页面要求禁止横屏 则需要在上一个页面写
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[UIDevice currentDevice] setValue: [NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];
}
这样就做到横竖屏切换啦