【问题标题】:ViewController Not RotatingViewController 不旋转
【发布时间】:2012-09-13 09:28:51
【问题描述】:

我一直在使用某个应用程序时遇到问题,并且需要轮换某些视图。

我已经知道标签栏控制器中的任何视图都不能旋转,除非允许所有视图旋转。我也知道导航控制器中的任何视图都不能旋转,除非最上面的视图被允许旋转。

我主要使用 IB 来设置我的应用程序。

MainWindow.xib 中,我有AppDelegate ObjectWindowTabBarController,然后是单独的UIViewController

在选项卡栏的一个选项卡中,我有一个 IBAction 链接到 UIButton,代码如下:

-(IBAction)stuff {
[self presentViewController:buletinss animated:YES completion:nil];
}

视图控制器在头文件中声明为IBOutlet,并从该选项卡类链接到UIViewController。然后在 IB 中,我将该视图控制器的类设置为我设置的 UIViewController 类,并返回 YES 以允许它旋转。

但是,它仍然不会旋转。

我认为由于它不是标签栏的一部分,也不是从导航控制器推动的,所以它可以旋转,但我没有运气。请帮忙?

这里是完整的代码:

首先,带有按钮的视图的 .h 和 .m:

#import <UIKit/UIKit.h>

@interface BulletinViewController : UIViewController {
IBOutlet UIWebView *worship;
IBOutlet UIActivityIndicatorView *activity;
NSTimer *timer;
IBOutlet UIViewController *buletinss;

}
-(IBAction)stuff;
@property (nonatomic, retain) UIActivityIndicatorView *activity;

@end

和.m

#import "BulletinViewController.h"

@implementation BulletinViewController

-(IBAction)stuff {

[self presentViewController:buletinss animated:YES completion:nil];
}

现在是它所呈现的视图的 .h 和 .m

#import <UIKit/UIKit.h>

@interface TestBulletinViewController : UIViewController

@end

和.m

#import "TestBulletinViewController.h"

@implementation TestBulletinViewController


-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation         {
return YES;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

【问题讨论】:

  • 给出一个完整的代码来检测你的错误
  • @CReaTuS 好的,查看完整代码的编辑
  • 它不会旋转是什么意思?您的意思是您以纵向方式握住设备,但呈现的视图以横向方式显示?你的意思是呈现的视图出现然后你旋转设备并且视图没有补偿?什么?
  • @matt 第二个。它以纵向加载(这是我想要的),但是当我旋转时,视图不会补偿。
  • @user717452 结果如何?

标签: iphone xcode ipad uiviewcontroller autorotate


【解决方案1】:

尝试更改此代码

[self presentViewController:buletinss animated:YES completion:nil];

[self presentModalViewController:buletinss animated:YES];

UPD:在 iOS 6 中您必须:

1)

替换

[window addSubview:buletinss.view];

window.rootViewController = buletinss;

2)

添加此代码行

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

【讨论】:

  • 正好相反; presentModalViewController 最终将被弃用。
  • 谁说的?关于这个的官方链接在哪里?
  • 寻找自己。阅读标题。我引用:“[presentModalViewController] 已被 presentViewController:animated:completion: 取代。它将被弃用,相应地计划。”建议某人切换 presentModalViewController 是错误的(并且与问题无关)。
  • 现在 iOS 6 是公开的,我可以“揭示”presentModalViewController 实际上现在已正式弃用。 developer.apple.com/library/ios/#documentation/uikit/reference/… 始终注意标题,因为此弃用已提前明确发出。
【解决方案2】:

如果不查看您的项目,很难知道发生了什么。您正在做一件非常奇怪的事情:为什么要从 nib 加载视图控制器?你是说:

IBOutlet UIViewController *buletinss;

为什么?为什么不显式实例化 BulletinViewController 并将 ivar 设置为该值?

我敢打赌,问题在于在笔尖中,这个对象不是 BulletinViewController。它可能只是一个通用的 UIViewController。因此,您的 BulletinViewController 代码无关紧要;它从来没有运行过。相反,你有一个通用的 UIViewController 只能旋转到纵向。但这只是猜测。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-30
    • 1970-01-01
    相关资源
    最近更新 更多