iOS 6.0中的界面方向 [英] Interface orientation in iOS 6.0

查看:86
本文介绍了iOS 6.0中的界面方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iOS 6.0中使用以下方法支持界面方向:

How to use the following methods to support interface orientation in iOS 6.0:

shouldAutorotate

supportedInterfaceOrientations

preferredInterfaceOrientationForPresentation

在iOS 6.0中不推荐使用shouldAutorotateToInterfaceOrientation。

As "shouldAutorotateToInterfaceOrientation" is deprecated in iOS 6.0.

请提供代码片段以支持您的答案。

Please provide code snippets to support your answers.

谢谢。

推荐答案

iOS 5中不推荐使用的方法:

Deprecated method in iOS 5:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

iOS 6中的替换以及上述不推荐使用的iOS 5方法的等价物:

Replacement in iOS 6 and equivalent of this deprecated iOS 5 method above:

- (BOOL) shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeRight;
}

希望这有帮助。

#import "FirstViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self)
    {
        // Custom initialization
    }

    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationMaskPortrait;
}

[#edit 2:仅支持横向的应用程序的示例代码iOS 5和iOS 6]

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

- (BOOL)shouldAutorotate {

    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {

    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {

    return UIInterfaceOrientationLandscapeLeft;
}

这篇关于iOS 6.0中的界面方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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