我正在开发一个只使用横向方向的iPad应用程序。它有一个功能,可以点击一个UIImageView来访问相机胶卷,并从中挑选一张照片,然后显示出来。
应用程序是这样的。我有一个表格vie,当你点击‘+’按钮时,它会加载一个新的视图,将新数据添加到数据库中。这个' add‘页面以模式加载。
问题是,每当相机胶卷加载时,它会自动将方向更改为纵向,而我希望整个应用程序保持横向。
所以有人有解决方案吗?
视频链接:Video showing the problem
发布于 2013-09-16 12:16:07
如果您的应用程序是基于UINavigationController的,则使用以下类别方法
@implementation UINavigationController (Rotation)
#pragma From UINavigationController
- (BOOL)shouldAutorotate {
return TRUE;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft || UIInterfaceOrientationMaskLandscapeRight;
} 发布于 2013-09-16 12:22:49
对于横向模式ViewController,
#pragma mark - iOS 5.0 and up Rotation Methods
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationMaskLandscape;
}
#pragma mark - iOS 6.0 and up Rotation Methods
- (NSUInteger)supportedInterfaceOrientations;
{
return UIInterfaceOrientationMaskLandscape;
}如果您使用的是navigationController,请像这样创建一个类别。
@interface UINavigationController (Rotation_IOS6)
@end
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return [[self topViewController] supportedInterfaceOrientations];
}
@end发布于 2013-09-16 12:43:20
尝尝这个。并使用所需的方向,如下所示。
// For responding to the user accepting a newly-captured picture or movie
- (void) imagePickerController: (UIImagePickerController *) picker
didFinishPickingMediaWithInfo: (NSDictionary *) info {
UIImage *originalImage, *editedImage;
editedImage = (UIImage *) [info objectForKey:
UIImagePickerControllerEditedImage];
originalImage = (UIImage *) [info objectForKey:
UIImagePickerControllerOriginalImage];
if (originalImage) {
[uploadImageBtn setHidden:NO];
UIImage* newImage ;
switch (originalImage.imageOrientation) {
case UIImageOrientationUp: //Left
case UIImageOrientationDown: //Right
{
newImage = [UIImage imageWithCGImage:originalImage.CGImage scale:originalImage.scale orientation:UIImageOrientationUp];
}
break;
case UIImageOrientationLeft: //Down
case UIImageOrientationRight: //Up
{
newImage = originalImage;
}
break;
default:
break;
}
capturedImage.image = newImage;
}
[cameraUI dismissModalViewControllerAnimated: YES];
}https://stackoverflow.com/questions/18820275
复制相似问题