gpt4 book ai didi

iphone - iOS 6.0 中的界面方向

转载 作者:IT王子 更新时间:2023-10-29 07:55:34 27 4
gpt4 key购买 nike

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

shouldAutorotate

supportedInterfaceOrientations

preferredInterfaceOrientationForPresentation

因为“shouldAutorotateToInterfaceOrientation”在 iOS 6.0 中已弃用。

请提供代码片段来支持您的回答。

谢谢。

最佳答案

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 方法的等价物:

- (BOOL) shouldAutorotate
{
return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}

希望这对您有所帮助。


[编辑 #1:添加了我的 UIViewController,它在 iPhone 6.0 模拟器上的 XCode 4.5 中以纵向模式成功启动]

#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;
}

关于iphone - iOS 6.0 中的界面方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12404556/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com