ios - UIImagePickerController 在设备旋转时旋转 iOS 7

标签 ios

我有一个 UIImagePickerController,我希望它的方向始终保持在纵向模式。该应用程序本身设置为纵向模式,但 UIImagePickerController 改变了方向。我用代码创建了一个自定义 UIImagePickerController:

#import "ViewControllerImage.h"

@interface ViewControllerImage ()
- (BOOL)shouldAutorotate;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
- (NSUInteger)supportedInterfaceOrientations;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
@end

@implementation ViewControllerImage

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (NSUInteger)supportedInterfaceOrientations {

return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotate {

return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

我以这种方式呈现:

ViewControllerImage *picker = [[ViewControllerImage alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentViewController:picker animated:YES completion:nil];

代码不工作 Controller 仍然旋转。为什么?

最佳答案

最简单的解决方案 - 在项目文件中允许纵向模式。

作为第二种解决方案 - 尝试将以下代码添加到您的 appdelegate:

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

关于ios - UIImagePickerController 在设备旋转时旋转 iOS 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18932095/

相关文章:

ios - 如何将 iOS 应用程序从一个开发者帐户转移到另一个开发者帐户?

ios - UIimage 没有出现在 iOS 中的 ScrollView 上

iphone - iCloud 和 UIDocument : Is there a way to clean transaction logs

cocoa-touch - 如何只允许 180 度自转?

iOS 7 Safari 自动收缩/隐藏 UI 元素在滚动时不起作用

javascript - Cordova 为 iOS 中的 click() 事件增加了 350 毫秒的延迟

ios - Google plus sdk 链接器错误 ios

ios - 来自扩展的 UIAlertController

iPhone:解析具有阿拉伯语内容的 Xml 显示空值

ios - Unicode在iOS中无法正常工作