iPhone-5 compatible issue

為{幸葍}努か 提交于 2020-01-15 11:49:07

问题


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.


回答1:


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




回答2:


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 !!!!!!



来源:https://stackoverflow.com/questions/13630851/iphone-5-compatible-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!