我正在使用仅使用横向方向的iPad应用。它有一个功能,点击UIImageView访问相机胶卷,然后从那里选择一张照片,然后显示它。
该应用程序是这样的。我有一张表,当你点击“+”按钮时,它会加载一个新视图,将新数据添加到数据库中。这个“添加”页面以模态模式加载。
问题在于,每当相机胶卷被加载时,它会自动将方向更改为肖像,我希望整个应用程序保持横向。
所以任何人都有解决方案吗?
答案 0 :(得分:0)
如果您的应用程序基于UINavigationController,则使用以下类别方法
@implementation UINavigationController (Rotation)
#pragma From UINavigationController
- (BOOL)shouldAutorotate {
return TRUE;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeLeft || UIInterfaceOrientationMaskLandscapeRight;
}
答案 1 :(得分:0)
对于横向模式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
答案 2 :(得分:0)
试试这个。并使用所需的方向,如下所示。
// 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];
}