2016-06-11 61 views
0

我的应用程序处于横向模式,我想打开画廊并选择视频,但我收到错误消息。是否有任何方式使用UIImagePickerController横向模式或任何其他方式?有可能在iOS横向模式下使用UIImagePickerController?

+0

[检查此链接的景观应用](http://stackoverflow.com/questions/12551247/autorotate-a-single-uiviewcontroller-in-ios-6-with-uitabbar) &HTTP://计算器.COM /问题/ 19374237 /使用-的UIImagePickerController式景观的方向 –

回答

0
- (NSUInteger)supportedInterfaceOrientations{ 
return UIInterfaceOrientationMaskLandscape; 
} 

这应该有效。如果你的应用只允许肖像。你必须在应用程序委托中做一些额外的工作。您需要设置一个布尔属性,将其称为restrictRotation。然后包括AppDelegate.h在你的类,并设置restrictRotation为真时,你需要再旋转它

-(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; 
} 

这应该有助于

0

在你ViewController.m

使图像选取器控制器的子类(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只支持肖像模式。 如果您不支持纵向“全局”,图像选择器将因为没有可用的方向而崩溃。

相关问题