IPhone 4/4S adaptation iphone5 process experience full record

Source: Internet
Author: User

IPhone 4/4S application upgrade adaptation iphone5 there are a lot of ways, and the principle of which is also found on the Internet. I will not talk much about this nonsense. I will briefly describe my process:

In combination, I chose to add XIB files.

Step 1:

Find the XIB file that needs to be adapted to iphone5 in the project for adaptation, and add it to aviewcontroller.

First, go to the project file directory, find the aviewcontroller. XIB file, copy it in the same folder, and rename it as the aviewcontroller_ip5.xib file.

Step 2:

Add aviewcontroller_ip5.xib to the project;

Because the aviewcontroller_ip5.xib file is a copy of aviewcontroller. XIB, we do not even need to associate it with the aviewcontroller. h/. M file. (If you manually create an XIB file, you need to associate it with a class. For the method, refer to: manually associate the XIB file)

Step 3:

Select view in aviewcontroller_ip5.xib and set the View Size to retina 4 full screen under simulbutes Inspector-> simulated metrics-> size on the right. The view is changed to 4 inch of iphone5.

Adjust the position of the elements in the XIB file as needed.

Step 4:

Add the following macro to the. M file of the Controller that needs to use aviewcontroller. XIB and aviewcontroller_ip5.xib to determine whether the device is iphone5.

#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

Then, make a judgment in the code that uses the aviewcontroller. XIB and aviewcontroller_ip5.xib files, as shown in the following example:

    if (iPhone5) {       IndexViewController *myIndexViewController = [[IndexViewController alloc]initWithNibName:@"IndexViewController_ip5" bundle:nil];        [self.view addSubview:myIndexViewController.view];    }else{       IndexViewController *myIndexViewController = [[IndexViewController alloc]initWithNibName:@"IndexViewController" bundle:nil];        [self.view addSubview:myIndexViewController.view];    }

OK, all done!

 

Debug:

Write code. If there are few errors, what is the fun?

Several problems you may encounter when using the above method:

 

1. System throw:

* ** Terminating app due to uncaught exception 'nsinternalinconsistencyexception', reason: 'Could not load nib in Bundle: 'nsbundle </var/mobile/applications/logs/Hall. APP> (loaded)'
Name 'userinfoonnavibar'

Cause: The NIB file cannot be loaded because of internal inconsistency and inconsistency;

The actual cause is that after I directly copied an XIB file created under xcode4.3 and renamed it, the system throws the above error when using the above method to adapt to iPhone 5 in xcode4.5.

Solution: Do not use the copy method. manually create an XIB file under xcode4.5.

2. A scrollview cannot be rolled;

Solution: Drag xcode 4.3 to the scrollview on the xib file to delete it, and drag a scollview to the xib file again under xcode4.5. Then associate it. You do not need to modify any code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.