0

我正在开发一个应用程序,我希望它可以在 iPhone 4 和 5 上使用,因为 iPhone 5 已将其尺寸更改为 4 英寸,所以我希望我的应用程序可以支持 4 英寸,但在 Xcode4.3 中是没有自动布局,正因为如此,不知有没有办法把显示屏幕尺寸改成4寸,非常感谢!

4

1 回答 1

1

您可以使用以下代码获取屏幕尺寸:

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以下是根据屏幕尺寸移动广告横幅视图的示例:

-(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变量,即使您的默认视图控制器命名为 RootViewController 之类的名称。

希望这可以帮助。如果您有任何问题,请随时发表评论!

于 2013-10-20T05:40:05.910 回答