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.