iphone - 如何在 xcode4.3 中获取和修改显示屏幕大小

标签 iphone ios xcode4.3

我正在开发一个应用程序,我希望它可以在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/

相关文章:

iPhone WebKit CSS 动画导致闪烁

ios - 从 BLE 数据包中解压字节数组

ios - CALayer.contents 无法在 AVMutableComposition 中正确呈现

core-data - Xcode 4.3中的核心数据和UIManagedDocument:无法合并模型

ios - 应用程序运行时播放音频

iphone - Objective-C:按帧播放视频

php - 未经身份验证发布 Twitter/Facebook 状态?

iphone - iOS 自定义菜单(导航 Controller ?)

ios - SSZipArchive "failed to open zip file"-- url.path 不是解决方案

iphone - UIBezierPath 路径太多 = 太慢?