IOS screen adaptation knowledge, ios screen adaptation

Source: Internet
Author: User

IOS screen adaptation knowledge, ios screen adaptation

I. rotating
Step 1: register the notification [[NSNotificationCenter defacenter center] addObserver: self
Selector: @ selector (changeFrames :)
Name: UIDeviceOrientationDidChangeNotification
Object: nil];
Second, process the received events
-(Void) changeFrames :( NSNotification *) notification {
NSLog (@ "change notification: % @", notification. userInfo );
Float width = [[UIScreen mainScreen] bounds]. size. width * [[UIScreen mainScreen] scale];
Float height = [[UIScreen mainScreen] bounds]. size. height * [[UIScreen mainScreen] scale];
If ([[UIDevice currentDevice] orientation] = UIInterfaceOrientationPortrait
| [[UIDevice currentDevice] orientation] = UIInterfaceOrientationPortraitUpsideDown ){
NSLog (@ ">>> portrait ");
Self. frame = CGRectMake (0, 0, height, width );
} Else {
NSLog (@ ">>> landscape ");
Self. frame = CGRectMake (0, 0, width, height );
}

NSLog (@ "view-> % @", self );
}

Ii. Obtain screen resolution
// Obtain the size of the current screen:
CGSize size_screen = [[UIScreenmainScreen] bounds]. size;
// Obtain the scaling rate:
CGFloat scale_screen = [UIScreen mainScreen]. scale;

At this time, the product of the width and height of the screen size and the scale is the corresponding resolution value.
CGRect sizeOfA4 = CGRectMake (0, 0,595,842); // when generating a PDF file, follow the A4 standard
CGRect sizeOfA5 = CGRectMake (0, 0,421,595); // when generating a PDF file, follow the A5 Standard
Note: whether scale = 1 or scale = 2, the settings of the standard sizeOfA4 and sizeOfA5 of the paper remain unchanged, because the width and height we usually set are logical points in the iOS system, not a real pixel!
[[UIScreenmainScreen] bounds]. size remains unchanged as long as the screen is scaled up or down. Systems with different scales will automatically zoom in or out, which is why all applications run smoothly in the 320x0000and 640x960 environments.

Iii. Device Standards
IPhone/iPod Touch (x)
General screen resolution: 320 pixels x 480 pixels
Retina resolution: 640 pixels x 960 pixels

IPad, iPad2/New iPad (x)
General screen 768 pixels x 1024 pixels
Retina screen 1536 pixels x 2048 pixels

Conversion Relationship (one Point on iPhone 3 is equivalent to one pixel, while one point on iPhone 4 is equivalent to four pixel ;)
1 point = 1 pixel image.png
Retina screen 1 point = 2 pixel image@2x.png


Iv. True machine and simulator judgment + device type judgment
# If defined (TARGET_IPHONE_SIMULATOR) & TARGET_IPHONE_SIMULATOR
NSLog (@ "on simulator ");
# Else
NSLog (@ "not on simulator ");
# Endif
Note: TARGET_ OS _IPHONE is 1 on both the real machine and simulator.
There are two methods to determine the device type:
1. UI_USER_INTERFACE_IDIOM () is differentiated (for ios 3.2 and later versions), But iphone and ipod cannot be distinguished.
If (UI_USER_INTERFACE_IDIOM () = UIUserInterfaceIdiomPad ){
// The device is ipad
} Else {
// The device is iphone or ipod
}
2. Use UIDevice. model for differentiation (ios 2.0> =)
NSString * deviceType = [UIDevice currentDevice]. model;
If ([deviceType isEqualToString: @ "iPhone"]) {
// IPhone
} Else if ([deviceType isetype tostring: @ "iPod touch"]) {
// IPod Touch
} Else {
// IPad
}


5. Obtain device information
// Software Information
NSLog (@ "sysname = % @", [[UIDevice currentDevice] systemName]); // system name
NSLog (@ "systemVersion = % @", [[UIDevice currentDevice] systemVersion]); // version
NSLog (@ "model = % @", [[UIDevice currentDevice] model]); // type (ipad, ipod, iphone) [[UIDevice currentDevice] userInterfaceIdiom] can only judge iphone and ipad
NSLog (@ "olduuid = % @", [[UIDevice currentDevice] uniqueIdentifier]); // The Unique Identification Code ios5.0 starts deprecated
NSLog (@ "name = % @", [[UIDevice currentDevice] name]); // device name
NSLog (@ "localizedModel = % @", [[UIDevice currentDevice] localizedModel]); // Local Mode
NSLog (@ "ios6UUID = % @", [[[UIDevice currentDevice] identifierForVendor] UUIDString]); // ios6.0 starts available

---------- Note: the following content is not tested, from http://www.cnblogs.com/mrhgw/archive/2012/06/27/2565798.html ---------------
// Hardware information
[UIDevice platform]; // platform
[UIDevice cpuFrequency]; // cpu Information
UIDevice busFrequency]; // Bus
[UIDevice totalMemory]; // total memory
UIDevice userMemory]; // memory in use
Bytes -----------------------------------------------------------------------------------------------------------------------------
// App Information
NSDictionary * infoDictionary = [[NSBundle mainBundle] infoDictionary];
CFShow (infoDictionary); // All plist content
// App name
NSString * app_Name = [infoDictionary objectForKey: @ "CFBundleDisplayName"];
// App version
NSString * app_Version = [infoDictionary objectForKey: @ "cfbundlepolicversionstring"];
// App build version
NSString * app_build = [infoDictionary objectForKey: @ "CFBundleVersion"];

Determine whether a camera exists
If ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
NSLog (@ "");
Else
NSLog (@ "no ");

6. Programmers only need to do three things for devices with different resolutions:
1. Provides app HD icons;
2.uiimage material @2x.png;
3. Download the adapted image from the Network (Judgment condition [[UIScreen mainScreen] respondsToSelector: @ selector (scale)] & [[UIScreen mainScreen] scale] = 2)
-The Point resolution of all iPhone and iPod Touch devices is 320 × 480, that is, the logical resolution is the same, ensuring that the App can run normally at high pixel resolution without modification, only the images in the App will be pulled up and displayed, which will affect the appearance and fail to take advantage of retina.
-All GCRectMake statements in the program are logical resolutions and do not affect the position and size! Game Development is the most useful, with little impact on common apps
-Question: How to perform relative layout ??? (AutoResizeMask and autoresizing 6.0 are available in autoLayout similar to android)

Related Article

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.