【问题标题】:Change Orientation for single view controller..?更改单视图控制器的方向..?
【发布时间】:2014-07-30 14:20:14
【问题描述】:

我有一个仅支持纵向模式的应用程序。但需要将单个视图控制器的方向更改为横向。我在这里看到了更多答案。

但我无法实现。我现在创建了新的单视图应用程序。视图控制器有一个按钮。我想在单击按钮时更改视图控制器的方向。

#import "pixViewController.h"
#import "pixNextViewController.h"
@interface pixViewController ()
- (IBAction)changeOrientation:(id)sender;

@end



@implementation pixViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

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

- (IBAction)changeOrientation:(id)sender {

}

@end

changeOrentaion 方法中应该有什么代码..?

【问题讨论】:

  • CGAffineTransform,也许?

标签: ios xcode uiviewcontroller uistatusbar orientation-changes


【解决方案1】:

您可以覆盖:

- (BOOL)shouldAutoRotate

对于您项目中的每个视图控制器,并为您希望允许旋转的视图控制器返回 YES。

然后,还覆盖supportedDeviceOrientations 并在其中指定您想要的内容。例如:

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

请务必在目标的常规设置中正确设置允许的方向。换句话说,让您的项目允许多个方向,但只是不允许在您不希望旋转的单个视图控制器类中进行旋转。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多