【问题标题】:it is possible to use UIImagePickerController in landscape mode in iOS?可以在 iOS 的横向模式下使用 UIImagePickerController 吗?
【发布时间】:2016-10-12 03:05:09
【问题描述】:

我的应用程序处于横向模式,我想打开图库并选择视频,但出现错误。有没有办法在横向模式下使用 UIImagePickerController 或任何其他替代方式?

【问题讨论】:

标签: ios objective-c uiimagepickercontroller


【解决方案1】:
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}

这应该可行。如果您的应用只允许纵向。您必须在应用程序委托中做一些额外的工作。你需要设置一个布尔属性,称之为restrictRotation。然后在你的类中包含 AppDelegate.h 并在需要旋转它时将 restrictRotation 设置为 true

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(self.restrictRotation)
    return UIInterfaceOrientationMaskPortrait;
else
    return UIInterfaceOrientationMaskAll;
}

然后在你的课堂上

- (void) orientationChanged:(NSNotification *)note
{
UIDevice * device = note.object;
switch(device.orientation)
{
    case UIDeviceOrientationPortrait:
        //do stuff
        break;
    case UIDeviceOrientationLandscapeLeft:
         //do stuff
        break;
    case UIDeviceOrientationLandscapeRight:
       //do stuff
        break;
    default:
        break;
   };
}
-(void) restrictRotation:(BOOL) restriction
{
     AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
appDelegate.restrictRotation = restriction;
}

应该有帮助

【讨论】:

    【解决方案2】:

    在你的ViewController.m:

    制作Image Picker Controller的子类(ViewController)

    @interface ViewController : UIImagePickerController
    
    @end
    
    @implementation ViewController
    
    // Disable Landscape mode.
    
        - (NSUInteger)supportedInterfaceOrientations{
    
            return UIInterfaceOrientationMaskLandscape;
        }
    @end
    

    使用以下代码:

    UIImagePickerController* picker = [[ViewController alloc] init];
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            picker.delegate = self; 
     // etc.... do like Just as Default ImagePicker Controller
    

    但请务必检查部署信息中的肖像,

    因为UIImagePickerController 只支持纵向模式。 如果您不支持“全局”人像,则图像选择器将崩溃,因为它没有可用的方向。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-12
      • 1970-01-01
      • 2019-04-21
      • 2012-03-01
      相关资源
      最近更新 更多