我正在开发一个应用程序,我希望它可以在iPhone 4和5上使用,因为iPhone 5已经将其尺寸更改为4英寸,所以我希望我的应用程序可以支持4英寸,但是在Xcode4中.3 没有自动布局,因此,我想知道是否有办法获取显示屏幕尺寸并将其更改为4英寸,非常感谢!
最佳答案
您可以使用以下代码获取屏幕尺寸:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
UIViewController *ViewController;
[self loadall];
if (screenBounds.size.height == 568) {
NSLog(@"User is using an iPhone 5+");
BOOL isUsingiPhone5 = YES;
}
else{
NSLog(@"User is using an iPhone 4s-");
BOOL isUsingiPhone5 = NO;
}
然后您可以相应地移动内容,使用 CGRect
下面是一个根据屏幕尺寸移动广告横幅 View 的示例:
-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
CGRect bannerFrame = banner.frame;
CGRect screenBounds = [[UIScreen mainScreen] bounds];
UIViewController *ViewController;
if (screenBounds.size.height == 568) {
//iPhone5+
bannerFrame.origin.x = 0;
bannerFrame.origin.y = 518;
banner.frame = bannerFrame;
}
else{
//iPhone4s-
}
NSLog(@"Showing ad, internet connection found.");
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[banner setAlpha:1];
[UIView commitAnimations];
}
else{
[banner setAlpha:0];
}
确保使用 ViewController
作为 UIViewController
变量,即使您的默认 View Controller 名为 RootViewController。
希望这对您有所帮助。如果您有任何问题,请随时发表评论!
关于iphone - 如何在 xcode4.3 中获取和修改显示屏幕大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19472813/