Manual adaptation of iOS code-only
First, let's talk about how to make your program support iPhone6 and 6 +. First, use the launch screen officially provided. xib, which can be viewed in the official documentation. The second method is similar to the previous iPhone 5, which is relatively simple. Add two special png images for iPhone 6 and 6 +.
IPhone 6: Name: Default-375w-667h@2x.png resolution: 750*1334
6 + name: Default-414w-736h@3x.png resolution: 1242*2208
Note:
If you want to enable "iPhone6, 6 plus optimization" on the app introduction page, you must use the first method. If you use the second method, "iPhone5 optimization" is displayed"
The following describes code-only adaptation.
First, the iPhone 5 interface must be fully adapted, In order to perfectly adapt to 6 and 6 Plus.
First, let's take a look at the size ratio of 5, 6, and 6 plus.
Obviously, we can see that the sizes and aspect ratios of these three screens are almost the same. Therefore, we can scale them in proportion to 6 and 6 plus screens based on 5.
In AppDelegate. h
1 2 |
@ Property float autoSizeScaleX; @ Property float autoSizeScaleY; |
In AppDelegate. m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# Define ScreenHeight [[UIScreen mainScreen] bounds]. size. height # Define ScreenWidth [[UIScreen mainScreen] bounds]. size. width -(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions { AppDelegate * myDelegate = [[UIApplication sharedApplication] delegate]; If (ScreenHeight> 480 ){ MyDelegate. autoSizeScaleX = ScreenWidth/320; MyDelegate. autoSizeScaleY = ScreenHeight/568; } Else { MyDelegate. autoSizeScaleX = 1.0; MyDelegate. autoSizeScaleY = 1.0; } } |
Because the height of the iPhone 4S screen is 480, when the screen size is greater than iPhone 4, autoSizeScaleX and autoSizeScaleY are the aspect ratio of the current screen and iPhone 5. For example,
If it is 5, autoSizeScaleX = 1, autoSizeScaleY = 1;
If it is 6, autoSizeScaleX = 1.171875, autoSizeScaleY = 1.17429577;
If it is 6 Plus, autoSizeScaleX = 1.29375, autoSizeScaleY = 1.2957;
After obtaining the proportional relationship, let's take a look at how to adapt to the Code setting interface.
CGRectMake (CGFloat x, CGFloat y, CGFloat width, CGFloat height) is a common dimension setting method. Now I have set a method similar to this.
In the. m file
1 2 3 4 5 6 7 8 9 10 11 |
UIImageView * imageview = [[UIImageView alloc] initWithFrame: CGRectMake1 (100,100, 50, 50)]; CG_INLINE CGRect CGRectMake1 (CGFloat x, CGFloat y, CGFloat width, CGFloat height) { AppDelegate * myDelegate = [[UIApplication sharedApplication] delegate]; CGRect rect; Rect. origin. x = x * myDelegate. autoSizeScaleX; rect. origin. y = y * myDelegate. autoSizeScaleY; Rect. size. width = width * myDelegate. autoSizeScaleX; rect. size. height = height * myDelegate. autoSizeScaleY; Return rect; } |
In this way, the btn button has the same position and size ratio of 5, 6 and 6 plus.
If the entire project is completed before adaptation, the advantages of this method are shown. In the face of dozens of engineering files, you only need to customize and replace your CGRectMake method, in addition, the storyBoradAutoLay method instantly completes most or even all of the adaptation. If you encounter tableView or other manual adjustments, you can.