Ios 如何防止方向旋转?

Ios 如何防止方向旋转?,ios,objective-c,rotation,Ios,Objective C,Rotation,我正在开发一款iPad应用程序,它只使用横向定向。它有一个功能,点击UIImageView以访问相机卷并从中拾取一张图片,然后显示它 应用程序是这样运行的。我有一个表vie,当您单击“+”按钮时,它将加载一个新视图以向数据库添加新数据。此“添加”页面以模式模式加载 问题是,每当装入相机卷时,它就会自动将方向更改为纵向,我希望整个应用程序保持横向 有人有办法吗 视频链接:如果您的应用程序基于UINavigationController,请使用以下分类方法 @implementation UINav

我正在开发一款iPad应用程序,它只使用横向定向。它有一个功能,点击UIImageView以访问相机卷并从中拾取一张图片,然后显示它

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

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

有人有办法吗


视频链接:

如果您的应用程序基于UINavigationController,请使用以下分类方法

@implementation UINavigationController (Rotation)

    #pragma From UINavigationController

    - (BOOL)shouldAutorotate {

        return TRUE;
    }
    - (NSUInteger)supportedInterfaceOrientations {

        return UIInterfaceOrientationMaskLandscapeLeft || UIInterfaceOrientationMaskLandscapeRight;
    }                                 

对于横向模式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

试试这个。并使用如下所示的所需方向

// 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];

}

在支持的界面方向中,是否启用横向模式?启用横向模式和禁用纵向模式。我在项目开始时就这样做了。仍然不起作用。[[UIApplication sharedApplication]设置状态BaroOrientation:UIInterfaceOrientation和scapeRight动画:否];在appdelegate didFinishLaunch方法中尝试此操作。无效。现在我想起来了,是因为我在使用iOS 7和Xcode 5吗?我错了还是你认为问题在于UIImageView处理图像?如果是这样的话,我认为这不是问题所在,因为问题出现在摄影机滚动视图加载时。不在我的应用程序中。请检查此[链接]()仍为空。。你知道,我想我不能改变这一点,因为camera roll是一个苹果的应用程序,我想我不能修改它的行为。我会在youtube上发布一段视频,让你看看发生了什么。