iPhone-5 compatible issue

2019-07-25 00:26发布

I had developed an ios app for ios 4.0.That was navigation based application.Now I want it also support for iPhone-5 I think I changed xib after checking device version,I am facing problem xib is changed but it's view Height is not changed.How it can possible if some else face this problem please share ideas with me.Thanks.

2条回答
叛逆
2楼-- · 2019-07-25 01:13

IN APP Delegate:-

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{



CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;

//----------------HERE WE SETUP FOR IPHONE 4/4s/iPod----------------------

if(iOSDeviceScreenSize.height == 480){


   self.viewController = [[ViewController alloc]   initWithNibName:@"ViewController_4inch" bundle:nil];

    NSLog(@"iPhone 4: %f", iOSDeviceScreenSize.height);

}

//----------------HERE WE SETUP FOR IPHONE 5----------------------

if(iOSDeviceScreenSize.height == 568){

    self.viewController = [[ViewController alloc]   initWithNibName:@"ViewController_5inch" bundle:nil];
     NSLog(@"iPhone 5: %f", iOSDeviceScreenSize.height);

}

 return YES;
 }

Its Works !!!!!!

查看更多
来,给爷笑一个
3楼-- · 2019-07-25 01:20

Set iOS 6 as the Base SDK and use the Auto Layout feature to make screens that can scale for all type of screens. You'll need Xcode 4.5 to do this.

Get started with Auto Layout here:
http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
http://www.raywenderlich.com/20897/beginning-auto-layout-part-2-of-2

If you still want to support iOS 4.0, have separate .xib files for different screen sizes and load them appropriately at launch.

To load different nib files based on your screen size, in your app delegate, you will need to add/replace the following code in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568) {
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_4inch" bundle:nil];
} else {
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
}

where ViewController_4inch is the name of the nib file that is designed for iPhone 5 screen

查看更多
登录 后发表回答