无法停止设备旋转 [英] unable to stop device rotation

查看:73
本文介绍了无法停止设备旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此处.其中一位好友回答并提出了解决方案.尽管该解决方案仅在少数视图控制器上起作用,但在视图上却无法正常工作.当我输入在选项卡上的Bar Items上具有TabController +导航控制器的视图控制器时,代码不起作用.并且视图可以旋转.

I have posted a question here . In which one buddy replied and gave solution. Although the solution is working on few view controllers but on view its not working. When I enter a view controller that has TabController + navigation controller on there tab Bar Items, the code doesn't work. and the views are able to rotate.

我在iOS 6.1上使用了以下代码

I used the Following code for iOS 6.1

//For iOS6
- (BOOL)shouldAutorotate {
    return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations {
   return UIInterfaceOrientationMaskPortrait;
}

我也必须在iOS 7中实现相同的功能. 请帮助

I have to implement the same thing in iOS 7 too. Please Help

推荐答案

由于我使用的是TabBarController,所以我得到的唯一可行的解​​决方案是创建类别.

Since I m using a TabBarController, the only working solution I got was to create a category.

所以只需创建一个类别

这是类别的.h类,我将其命名为AutoRotationtab

here's the .h class of the category, I named it AutoRotationtab

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

@interface UITabBarController (AutoRotationTab)

@end

这是类别的.m类

#import "UITabBarController+AutoRotationTab.h"

@implementation UITabBarController (AutoRotationTab)

-(BOOL)shouldAutorotate
{
if(globalvariable_shouldRotate)
{
    return YES;
}
else
{
    return NO;
}
}


- (NSUInteger)supportedInterfaceOrientations
{

if(globalvariable_shouldRotate)
{
    return UIInterfaceOrientationMaskAll;
}
else
{
    return UIInterfaceOrientationMaskPortrait;
}
}

只要创建此类别,然后查看魔术,它就会起作用

just make this category, and see the Magic, It works

这篇关于无法停止设备旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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