【问题标题】:How to stop to rotate one view controller with uinavigationcontroller? [duplicate]如何停止使用 uinavigationcontroller 旋转一个视图控制器? [复制]
【发布时间】:2014-05-07 08:22:26
【问题描述】:

嘿伙计们,我见过很多类似的问题,但无法找到任何解决方案。我正在使用情节提要创建一个通用应用程序,并拥有一个具有根视图控制器 v1 的导航控制器,因此最初的顶视图控制器是 v1。单击 v1 上的按钮时,它会推送视图控制器 v2。现在我希望该应用程序应该为除视图控制器 v2 之外的所有视图控制器向所有方向旋转。我检查了部署信息中的所有设备方向,并尝试创建 uinavigationcontroller 类别

#import <UIKit/UIKit.h>

@interface UINavigationController (autorotation)
-(BOOL)shouldAutorotate;
-(NSUInteger)supportedInterfaceOrientations;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
@end

#import "UINavigationController+autorotation.h"
#import "AboutViewController.h"

@implementation UINavigationController (autorotation)

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

-(BOOL)shouldAutorotate
{
   return [self.topViewController shouldAutorotate];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.topViewController preferredInterfaceOrientationForPresentation];
}

我的问题是应用程序正在为所有屏幕旋转,但我想如上所述停止视图控制器 v2 的旋转。我真的有我的两天请帮帮我

【问题讨论】:

  • 这个link 将对您有所帮助,因为我对其进行了测试并且它有效。不要忘记投票并勾选我的答案!

标签: objective-c ios7 uinavigationcontroller


【解决方案1】:
- (BOOL)shouldAutorotate
{
    id currentViewController = self.topViewController;

    if ([currentViewController isKindOfClass:[v2 class]])
        return NO;

    return YES;
}

//在你的代码中添加这个方法并告诉我它的工作与否。

【讨论】:

  • Rushabh 感谢您的快速回复,我已经在 v1 和 v2 中编写了此方法。还是不行
  • Rushabh,还有一个问题应该在何时以及调用多少次?对不起,愚蠢的问题
【解决方案2】:

This is a useful link i used once 它与您的要求相反,但您仍然可以使用它。

另一种方法是将它放在您不想旋转的视图中

- (BOOL) shouldAutorotate {
return NO; }

不要忘记将视图旋转到适当的 InterfaceOrientation,像这样

[self willAnimateRotationToInterfaceOrientation:1 duration:1];

你可以把它放在 viewWillApear 中;

【讨论】:

    猜你喜欢
    • 2013-10-12
    • 1970-01-01
    • 2016-07-05
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多