我的应用程序处于横向模式,我想打开图库并选择视频但我收到错误。有没有办法在横向模式或任何其他替代方式使用UIImagePickerController?
答案 0 :(得分:0)
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
这应该有效。如果您的应用只允许肖像。你必须在app delegate中做一些额外的工作。您需要设置一个布尔属性,称之为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;
}
那应该有帮助
答案 1 :(得分:0)
在ViewController.m
:
制作Image Picker Controller的SubClass(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
仅支持纵向模式。
如果你不支持肖像"全球"由于没有可用的方向,图像选择器会崩溃。