简体   繁体   English

制作一个适用于iPhone和iPad的应用程序

[英]make an app which is compatible for both iphone and ipad

I am using both device for make my application.my application is perfectly run in iPad but when i select device as iPhone 4inch there is an error occur in interface.below is picture. 我正在使用这两种设备来制作我的应用程序。我的应用程序可以在iPad上完美运行,但是当我将设备选择为iPhone 4inch时,界面出现错误。 you can see black color in top and bottom where did it came from? 您可以在顶部和底部看到黑色,它是从哪里来的?

在此处输入图片说明

and here is my code: 这是我的代码:

in app delegate: 在应用程序委托中:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
    {
        NSLog(@"Ipad ");
        [application setStatusBarStyle:UIStatusBarStyleLightContent];

        self.window.clipsToBounds =YES;

        self.window.frame =  CGRectMake(0,-20,self.window.frame.size.width,self.window.frame.size.height+20);
    }
    if
     (IS_IPHONE_5)
    {

        NSLog(@"Iphone %f ",[[UIScreen mainScreen] bounds].size.height);
        if ([[UIScreen mainScreen] bounds].size.height == 568) {

            [application setStatusBarStyle:UIStatusBarStyleLightContent];

            self.window.clipsToBounds =YES;

            self.window.frame =  CGRectMake(0,-20,self.window.frame.size.width,self.window.frame.size.height+20);
        }
    }

}

在此处输入图片说明

If you want to support app for iPhone 5 screen. 如果要支持iPhone 5屏幕的应用程序。 You should add image which enable app for iPhone 5 screen size. 您应该添加图片以启用适用于iPhone 5屏幕尺寸的应用程序。 This should be implement from xcode 4.5+ 这应该从xcode 4.5+开始实施

Add this image to your project 将此图像添加到您的项目中 Xcode屏幕截图 . To enable your apps to work with iPhone 5, you need to add a retina version of the launcher image. 为了使您的应用程序能够与iPhone 5配合使用,您需要添加启动器图像的视网膜版本。 It should be named Default-568h@2x.png 它应该命名为Default-568h@2x.png

Set the autoresizing mask of the center content to expand in both directions. 设置中心内容的自动调整大小蒙版以在两个方向上扩展。

view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

Otherwise you can change view size by below code which will make you screen to compatible with your iPhone 5 screen. 否则,您可以通过以下代码更改视图大小,这将使您的屏幕与iPhone 5屏幕兼容。

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
    // code for 4-inch screen
} else {
    // code for 3.5-inch screen
}

If you want to use compatible for both iPad and iPhone(standard, 3.5 inch, 4 inch), try this 如果要使用与iPad和iPhone兼容的设备(标准3.5英寸,4英寸),请尝试此操作

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
    if ([UIScreen mainScreen].scale == 2.0f) {
        CGSize result = [[UIScreen mainScreen] bounds].size;
        CGFloat scale = [UIScreen mainScreen].scale;
        result = CGSizeMake(result.width * scale, result.height * scale);

        if(result.height == 960){
            NSLog(@"iPhone 4, 4s Retina Resolution");
        }
        if(result.height == 1136){
            NSLog(@"iPhone 5 Resolution");
        }
        else {
            NSLog(@"iPhone Standard Resolution");
        }
    }
    else {
    //iPad
        if ([UIScreen mainScreen].scale == 2.0f) {
            NSLog(@"iPad Retina Resolution");
        } 
        else{
            NSLog(@"iPad Standard Resolution");
        }
}

为iPhone 5 640 * 1136添加默认的视网膜图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM