【发布时间】:2016-10-12 03:05:09
【问题描述】:
我的应用程序处于横向模式,我想打开图库并选择视频,但出现错误。有没有办法在横向模式下使用 UIImagePickerController 或任何其他替代方式?
【问题讨论】:
标签: ios objective-c uiimagepickercontroller
我的应用程序处于横向模式,我想打开图库并选择视频,但出现错误。有没有办法在横向模式下使用 UIImagePickerController 或任何其他替代方式?
【问题讨论】:
标签: ios objective-c uiimagepickercontroller
- (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;
}
应该有帮助
【讨论】:
在你的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 只支持纵向模式。
如果您不支持“全局”人像,则图像选择器将崩溃,因为它没有可用的方向。
【讨论】: