iOS7 iPad仅风景应用程序,使用UIImagePickerController [英] iOS7 iPad Landscape only app, using UIImagePickerController
问题描述
我相信这是一个常见的问题,许多答案不工作了,很多只是部分,如果你是在iOS7和你的iPad应用程序是景观只,但你想使用 UIImagePickerController
与来源 UIImagePickerControllerSourceTypePhotoLibrary
或 UIImagePickerControllerSourceTypeCamera
。
如何正确设置,所以它的工作100%?你不会得到混合的方向,并避免错误支持的方向没有共同的方向与应用程序, shouldAutorotate
返回是
。
如果您的iPad应用程式仅在所有情况下都是横向,只需执行以下3个步骤:
1)在您的应用程式委托中
(NSUInteger)应用程序:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAll;
}
2)创建类别标题
#importUIViewController + OrientationFix.h
@implementation UIViewController(OrientationFix)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
@end
3)类别实施 UIImagePickerController(OrientationFix)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
@end
注意:需要在任何地方导入这些类别,只需使用项目编译即可。
注意:在任何VC中不需要实现这些方法
注意:无需更改plist支持的方向
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
.
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
".
If your iPad app is landscape only in all conditions, just do these 3 steps :
1) In your app delegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAll;
}
2) Create a category header
#import "UIViewController+OrientationFix.h"
@implementation UIViewController (OrientationFix)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
@end
3) Create a category implementation
#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
Note: no need to implement these methods in any VC
Note: no need to change your plist supported orientations
This is tested and working under any conditions
这篇关于iOS7 iPad仅风景应用程序,使用UIImagePickerController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!