首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何保持方向不被旋转?

如何保持方向不被旋转?
EN

Stack Overflow用户
提问于 2013-09-16 12:09:16
回答 3查看 81关注 0票数 0

我正在开发一个只使用横向方向的iPad应用程序。它有一个功能,可以点击一个UIImageView来访问相机胶卷,并从中挑选一张照片,然后显示出来。

应用程序是这样的。我有一个表格vie,当你点击‘+’按钮时,它会加载一个新的视图,将新数据添加到数据库中。这个' add‘页面以模式加载。

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

所以有人有解决方案吗?

视频链接:Video showing the problem

EN

回答 3

Stack Overflow用户

发布于 2013-09-16 12:16:07

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

代码语言:javascript
运行
复制
@implementation UINavigationController (Rotation)

    #pragma From UINavigationController

    - (BOOL)shouldAutorotate {

        return TRUE;
    }
    - (NSUInteger)supportedInterfaceOrientations {

        return UIInterfaceOrientationMaskLandscapeLeft || UIInterfaceOrientationMaskLandscapeRight;
    }                                 
票数 0
EN

Stack Overflow用户

发布于 2013-09-16 12:22:49

对于横向模式ViewController,

代码语言:javascript
运行
复制
#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,请像这样创建一个类别。

代码语言:javascript
运行
复制
    @interface UINavigationController (Rotation_IOS6)

    @end

    @implementation UINavigationController (Rotation_IOS6)

    -(BOOL)shouldAutorotate
    {
        return YES;
    }

    - (NSUInteger)supportedInterfaceOrientations
    {
        return [[self topViewController] supportedInterfaceOrientations];
    }

@end
票数 0
EN

Stack Overflow用户

发布于 2013-09-16 12:43:20

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

代码语言:javascript
运行
复制
// 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];

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18820275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档