IOS7 / IOS8仅在视图控制器中允许纵向
我正在构建一个只有1个横向视图的iPhone应用程序,所以我想阻止其他所有的景观,我试过这个:
-(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; }
但它仍然在旋转
我建议您只为肖像模式制作应用程序,然后在需要横向模式时再使用横向模式。
首先,如前所述,单击 – >项目名称 – >常规 – >部署信息 – >仅选择设备方向的纵向。
其次,在你的AppDelegate.h
添加这个属性..
@property (nonatomic) BOOL fullScreenVideoIsPlaying;
然后,在你的AppDelegate.m
我将添加这个function..
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ if (self.fullScreenVideoIsPlaying == YES) { return UIInterfaceOrientationMaskAllButUpsideDown; } else { return UIInterfaceOrientationMaskPortrait; } }
执行此操作后,在视图控制器中您需要横向创建一个函数或只是将此代码添加到您的viewWillAppear
方法取决于您想要如何实现此目的。
((AppDelegate *)[[UIApplication sharedApplication] delegate]).fullScreenVideoIsPlaying = YES; [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
然后,为了设置回纵向模式,你这样做..
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; appDelegate.fullScreenVideoIsPlaying = NO; [self supportedInterfaceOrientations]; [self shouldAutorotate:UIInterfaceOrientationPortrait]; [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
您可能需要iOS 8的这些function..
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (BOOL)shouldAutorotate:(UIInterfaceOrientation)interfaceOrientation{ // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } -(NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait; }
我希望它有帮助.. 🙂
单击项目,然后从那里选择方向设置。
- 在ViewContollers之间共享信息
- FBSDKLoginManager:体系结构x86_64 +链接器命令的未定义符号失败,退出代码为1
- Apple开发中的库,API,框架和SDK之间的关系。
- 如何从上传的iPhone照片获取正确的经纬度?
- NSURLSessionTaskauthentication挑战completionHandler和NSURLAuthenticationChallenge客户端
- 一个UIDatePicker用于多个字段 – 设置date时EXC_BAD_ACCESS
- 视图和视图控制器
- iOS中静态库的自定义Xcode模板
- 当从UIActivityViewController调用WhatsApp冻结后收件人被选中