Itz*_*984 5 iphone objective-c uiimagepickercontroller ios
使用iOS 8.3
我在横向模式下有一个视图,我正在尝试打开一个仅限肖像的视图控制器.每次我尝试打开它,应用程序崩溃.
我已经阅读了这个官方的苹果答案,基本上建议做以下事情:
在app委托中:
@implementation AppDelegate
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
return UIInterfaceOrientationMaskAll;
else /* iphone */
return UIInterfaceOrientationMaskAllButUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
Run Code Online (Sandbox Code Playgroud)
所以我有,但我仍然得到这个崩溃消息:
Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [PUUIAlbumListViewController shouldAutorotate] is returning YES
Run Code Online (Sandbox Code Playgroud)
在项目常规设置中,我有以下(不应根据苹果的答案进行更改):
我可以看到这些函数实际上被调用但没有任何帮助.有什么想法吗?
我之前读过的一些问题:
如何在iOS 6中强制UIViewController为Portrait方向
Swi*_*ect 11
概要: application(_:, supportedInterfaceOrientationsForWindow) -> Int 覆盖General> Deployment Info.因此,一旦您supportedInterfaceOrientationsForWindow在应用程序委托中提供,您就可以完全忽略该.plist .请参阅说明UIInterfaceOrientationMaskPortrait.
在Obj-C和Swift的每一个方向尝试过上面的代码,我得到的唯一一次......
'UIApplicationInvalidInterfaceOrientation',原因:'支持的方向与应用程序没有共同的方向,[ViewController shouldAutorotate]返回YES'
...那时候:
UIInterfaceOrientationPortrait而不是UIInterfaceOrientationMaskPortrait(掩码是这里的关键字)supportedInterfaceOrientations返回未列出的掩码supportedInterfaceOrientationsForWindowA.将此块放在采用UIApplicationDelegate协议的类中(通常AppDelegate.m或AppDelegate.swift):
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
return UIInterfaceOrientationMaskAll;
else /* iphone */
return UIInterfaceOrientationMaskAllButUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)
supportedInterfaceOrientations将覆盖部署信息,并允许在运行时动态区分iPhone和iPad.
B.将此块放在UIViewController您想要特定行为的子类中(通常CustomViewController.m或CustomViewController.swift):
OBJ-C
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
迅速
override func supportedInterfaceOrientations() -> Int {
let supported = UIInterfaceOrientationMask.Portrait.rawValue
return Int(supported)
}
Run Code Online (Sandbox Code Playgroud)
经过测试的iOS 8.4
| 归档时间: |
|
| 查看次数: |
10880 次 |
| 最近记录: |