0

我正在开发一个仅使用横向的 iPad 应用程序。它具有单击 UIImageView 以访问相机胶卷并从中选择图片然后显示它的功能。

该应用程序是这样的。我有一个表格,当您单击“+”按钮时,它会加载一个新视图以将新数据添加到数据库中。此“添加”页面以模式模式加载。

问题是,每当加载相机胶卷时,它会自动将方向更改为纵向,我希望整个应用程序保持横向。

所以有人有解决方案吗?

视频链接: 显示问题的视频

4

3 回答 3

0

如果您的应用程序基于 UINavigationController 则使用以下类别方法

@implementation UINavigationController (Rotation)

    #pragma From UINavigationController

    - (BOOL)shouldAutorotate {

        return TRUE;
    }
    - (NSUInteger)supportedInterfaceOrientations {

        return UIInterfaceOrientationMaskLandscapeLeft || UIInterfaceOrientationMaskLandscapeRight;
    }                                 
于 2013-09-16T04:16:06.947 回答
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];

}
于 2013-09-16T04:43:20.420 回答
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
于 2013-09-16T04:22:48.757 回答