【问题标题】:Landscape orientation image picker.横向图像选择器。
【发布时间】:2014-04-12 16:29:29
【问题描述】:

我正在创建一个仅限横向的应用,它使用图像选择器控件。

浏览该网站,我发现苹果出于某种原因只允许肖像。如果这意味着用户可以从库中选择一张照片,我可以将其翻转为纵向。 下面是我的代码,它给出了一个关于它处于横向模式的错误。我该如何解决这个问题,说可以将其翻转为纵向。谢谢

-(IBAction)takePhoto{
takePicker = [[UIImagePickerController alloc]init];
takePicker.delegate = self;
[takePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:takePicker animated:YES completion:NULL];

}
-(IBAction)chooseExisiting{
choosePicker = [[UIImagePickerController alloc]init];
choosePicker.delegate = self;
[choosePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:choosePicker animated:YES completion:NULL];

}

【问题讨论】:

    标签: ios iphone objective-c uiimagepickercontroller


    【解决方案1】:

    您不必在纵向模式下使用 ImagePickerController。 只需将其子类化以在横向模式下打开:

    @interface NonRotatingUIImagePickerController : UIImagePickerController
    @end
    
    @implementation NonRotatingUIImagePickerController
    - (BOOL)shouldAutorotate
    {
        return NO;
    }
    @end
    

    之后,您可以在该类中使用您的代码。

    -(IBAction)takePhoto {
    takePicker = [[NonRotatingUIImagePickerController alloc]init];
    takePicker.delegate = self;
    [takePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
    [self presentViewController:takePicker animated:YES completion:NULL];
    }
    
    -(IBAction)chooseExisiting{
    choosePicker = [[NonRotatingUIImagePickerController alloc]init];
    choosePicker.delegate = self;
    [choosePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    [self presentViewController:choosePicker animated:YES completion:NULL];
    }
    

    【讨论】:

    • 对不起,这在 Swift 3 中对我不起作用。即使我还覆盖了supportedInterfaceOrientations,我也会得到这个异常:'UIApplicationInvalidInterfaceOrientation',原因:'支持的方向与应用程序没有共同的方向,并且[PUUIAlbumListViewController shouldAutorotate] 返回 YES
    • 对不起,所有解决方案都不适合我。当我允许 UIImagePickerController 为纵向并导出所选视频时,它会以一些奇怪的方式旋转。有人有其他想法吗?
    【解决方案2】:

    为什么会出现错误?为什么不直接以纵向显示图像选择器?人们足够聪明,可以旋转他们的设备。或者您可以编写自己的横向图像选择器,或使用几个可用的开源软件之一。

    【讨论】:

    • 这就是我现在要做的。所以当我取消选择它时,我需要选择肖像。我是否需要将代码放入每个单独的视图控制器中,告诉它保持横向?
    • 一开始我只选择了纵向和横向,然后每个我只想出现在横向中的视图控制器都输入了下面的代码。 - (BOOL) shouldAutorotate { 返回 YES; } - (NSUInteger)supportedInterfaceOrientations{ 返回 UIInterfaceOrientationMaskLandscape; }
    猜你喜欢
    • 2013-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多