强制将方向设为人像模式 [英] Force orientation to Portrait Mode

查看:117
本文介绍了强制将方向设为人像模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所有应用程序都处于纵向模式,但是我拥有一个处于横向模式的viewcontroller作为图像库.

I have all the app in portrait mode, but I have one of the viewcontroller in landscape mode to be a gallery of images.

在项目摘要"选项卡上启用"LandscapeLeft"模式,因此我必须在Viewcontroller的其余部分中禁用这种旋转方式,除了在图片库的VC中.

On the tab Project Summary enable LandscapeLeft mode, so I have to disable the rotation this way in the rest of the Viewcontroller, except in the VC of the image gallery.

我想将旋转保持在纵向模式,要执行此操作并阻止所有VC纵向,我使用了以下代码

I want to keep the rotation in Portrait mode, to do this and to block all the VC portrait, I used the following code

-(BOOL)shouldAutorotate{
return YES;
}

-(NSInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
}
return UIInterfaceOrientationPortrait;
}

这,让我在以前的VC中保持横向模式,应该将其旋转到纵向.

This, keep me the landscape mode in the previous VC , when it should be rotated to Portrait.

有什么主意吗?

推荐答案

对于纵向模式VC,

#pragma mark iOS 5 Orientation Support

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

     return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

#pragma mark iOS 6 Orientation Support

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

对于横向模式VC,

#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,

If you are using navigationController,

创建这样的类别

    @interface UINavigationController (Rotation_IOS6)

    @end

    @implementation UINavigationController (Rotation_IOS6)

    -(BOOL)shouldAutorotate
    {
        if([self.visibleViewController isMemberOfClass:NSClassFromString(@"YourLandscapeViewController")])
        {
            return UIInterfaceOrientationMaskLandscape
        }
        return NO;
    }

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

    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        if([self.visibleViewController isMemberOfClass:NSClassFromString(@"YourLandscapeViewController")])
        {
            return UIInterfaceOrientationMaskLandscape
        }
        return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
    }

@end

这篇关于强制将方向设为人像模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆