如何使应用程序视图与 iPhone 6 和 6 plus 兼容
Posted
技术标签:
【中文标题】如何使应用程序视图与 iPhone 6 和 6 plus 兼容【英文标题】:How to make app views compatible with iPhone 6 and 6 plus 【发布时间】:2014-10-18 11:37:12 【问题描述】:我有 XIB 项目(新闻应用)所以它支持(iPhone 4 + 5 + 5s)
我想兼容 iPhone 6 和 6 plus
所以我创建了新文件 Xib,现在我有 5 个这样的 Xib 文件:
MainViewController.xib
MainViewController_568.xib
MainViewController_667.xib
MainViewController_736.xib
所以当我想通过按钮从视图转移到另一个视图时,我下了这个命令:-
- (IBAction)MainViewController:(UIButton *)sender
MainViewController *YourApp = [[MainViewController alloc] init];
if (self.view.bounds.size.height >= 667)
YourApp = [[MainViewController alloc] initWithNibName:@"MainViewController_667" bundle:nil];
else
if (self.view.bounds.size.height >= 568)
YourApp = [[MainViewController alloc] initWithNibName:@"MainViewController_568" bundle:nil];
else
YourApp = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
//favController.parent = self;
[self presentModalViewController:YourApp animated:NO];
[YourApp release];
//PP_RELEASE(YourApp);
但它没有响应。
【问题讨论】:
苹果提供了自动布局使用 【参考方案1】:请使用此代码
- (IBAction)MainViewController:(UIButton *)sender
MainViewController *YourApp = [[MainViewController alloc] init];
if (self.view.bounds.size.height == 736)
YourApp = [[MainViewController alloc] initWithNibName:@"MainViewController_736" bundle:nil];
else if (self.view.bounds.size.height == 667)
YourApp = [[MainViewController alloc] initWithNibName:@"MainViewController_667" bundle:nil];
else if (self.view.bounds.size.height == 568)
YourApp = [[MainViewController alloc] initWithNibName:@"MainViewController_568" bundle:nil];
else
YourApp = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
//favController.parent = self;
[self presentModalViewController:YourApp animated:NO];
[YourApp release];
//PP_RELEASE(YourApp);
【讨论】:
【参考方案2】:试试这个代码,它可能对你有帮助
- (IBAction)MainViewController:(UIButton *)sender
MainViewController *YourApp = [[MainViewController alloc] init];
if ( [UIScreen mainScreen].bounds.size.height == 736)
YourApp = [[MainViewController alloc] initWithNibName:@"MainViewController_736" bundle:nil];
else if ([UIScreen mainScreen].bounds.size.height == 667)
YourApp = [[MainViewController alloc] initWithNibName:@"MainViewController_667" bundle:nil];
else if ([UIScreen mainScreen].bounds.size.height == 568)
YourApp = [[MainViewController alloc] initWithNibName:@"MainViewController_568" bundle:nil];
else
YourApp = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
//favController.parent = self;
[self presentModalViewController:YourApp animated:NO];
[YourApp release];
//PP_RELEASE(YourApp);
【讨论】:
以上是关于如何使应用程序视图与 iPhone 6 和 6 plus 兼容的主要内容,如果未能解决你的问题,请参考以下文章
iOS 7 状态栏在 iPhone 应用程序中回到 iOS 6 默认样式?
iOS 7 状态栏在 iPhone 应用程序中回到 iOS 6 默认样式?
iOS 7 状态栏在 iPhone 应用程序中回到 iOS 6 默认样式?