iOS7 iPad Landscape 仅应用程序,使用 UIImagePickerController [英] iOS7 iPad Landscape only app, using UIImagePickerController

查看:22
本文介绍了iOS7 iPad Landscape 仅应用程序,使用 UIImagePickerController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信这是一个常见问题,许多答案不再有效,许多只是部分答案,如果您使用的是 iOS7 并且您的 iPad 应用程序仅为横向,但您想使用 UIImagePickerController使用源 UIImagePickerControllerSourceTypePhotoLibraryUIImagePickerControllerSourceTypeCamera.

I believe this is a common issue and many answers don't work anymore, many just partial, if you are under iOS7 and your iPad app is Landscape only, but you want to use the UIImagePickerController with source UIImagePickerControllerSourceTypePhotoLibrary or UIImagePickerControllerSourceTypeCamera.

如何正确设置,使其 100% 工作?而且您不会得到混合方向并避免错误支持的方向与应用程序没有共同的方向,并且 shouldAutorotate 返回 YES".

How to set it right, so it's working 100%? And you don't get mixed orientations and avoid the error "Supported orientations has no common orientation with the application, and shouldAutorotate returns YES".

推荐答案

如果您的 iPad 应用程序仅在所有条件下都是横向的,只需执行以下 3 个步骤:

If your iPad app is landscape only in all conditions, just do these 3 steps :

1) 在您的应用委托中

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return UIInterfaceOrientationMaskAll;
}

2) 创建类别标题

#import "UIViewController+OrientationFix.h"

@implementation UIViewController (OrientationFix)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

@end

3) 创建一个类别实现

#import "UIImagePickerController+OrientationFix.h"

@implementation UIImagePickerController (OrientationFix)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

@end

注意:您不需要在任何地方导入这些类别,只要它们与项目一起编译即可

Note: You don't need to import these categories anywhere, just enough they are compiled with the project

注意:不需要在任何VC中实现这些方法

Note: no need to implement these methods in any VC

注意:无需更改 plist 支持的方向

Note: no need to change your plist supported orientations

这是在任何条件下测试和工作

这篇关于iOS7 iPad Landscape 仅应用程序,使用 UIImagePickerController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆