iOS screen adaptation knowledge

Source: Internet
Author: User
Tags unique id

First, rotating processing
First step: Registration notice [[Nsnotificationcenter Defaultcenter] Addobserver:self
Selector: @selector (changeframes:)
Name:uideviceorientationdidchangenotification
Object:nil];
Second: Handling Receive 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);
}

Second, get the screen resolution
Get the current screen size:
Cgsize Size_screen = [[Uiscreenmainscreen]bounds].size;
Get Zoom Rate:
CGFloat scale_screen = [UIScreen mainscreen].scale;

The product of the width and height of the screen size is the corresponding resolution value.
CGRect sizeOfA4 = CGRectMake (0, 0, 595, 842);//A4 standard when generating PDF files
CGRect sizeOfA5 = CGRectMake (0, 0, 421, 595);//A5 standard when generating PDF files
Note: Regardless of scale=1 or scale=2, the standard sizeOfA4 and sizeOfA5 settings for the paper are the same, because the width we normally set is a logical point in the iOS system, not a real pixel!
As long as the screen is scaled up and down, [[Uiscreenmainscreen]bounds].size is not changed.] Systems with different scale will automatically zoom in or out, which is why all applications operate in 320x480 and 640x960 environments without discrimination.

Three, equipment standards
Iphone/ipod Touch (320 points x 480 points)
Pu resolution 320 pixels x 480 pixels
Retina resolution 640 pixels x 960 pixels

Ipad,ipad2/new IPad (768 dots x 1024 dots)
Pu 768 pixels x 1024 pixels
Retina screen 1536 pixels x 2048 pixels

Conversion relationship (1 point on IPhone3 is equivalent to 1 pixel, while iPhone4 1 point equals 4 pixel;)
Pu 1 points = 1 pixels image.png
Retina Screen 1 dots = 2 pixels [email protected]


Four, real machine and simulator judgment + equipment type judgment
#if defined (target_iphone_simulator) && Target_iphone_simulator
NSLog (@ "on simulator");
#else
NSLog (@ "not on simulator");
#endif
Note: The Target_os_iphone is 1 on both the real machine and the simulator.
There are two ways to determine the type of device:
1. Ui_user_interface_idiom () differentiate (iOS 3.2 +), but can't differentiate between iphone and ipod
if (ui_user_interface_idiom () = = Uiuserinterfaceidiompad) {
Device for ipad
} else {
Device for iphone or ipod
}
2. Use Uidevice.model to differentiate (iOS 2.0 >=)
NSString *devicetype = [Uidevice currentdevice].model;
if ([DeviceType isequaltostring:@ "IPhone"]) {
Iphone
}else if ([DeviceType isequaltostring:@ "IPod Touch"]) {
IPod Touch
}else {
Ipad
}


V. Access to equipment-related information
Software information
NSLog (@ "sysname=%@", [[Uidevice Currentdevice] systemName]);//System name
NSLog (@ "systemversion=%@", [[Uidevice Currentdevice] systemversion]); Version number
NSLog (@ "model=%@", [[Uidevice Currentdevice] model]); Type (ipad, ipod, iphone) and [[Uidevice Currentdevice] userinterfaceidiom] can only judge iphone and ipad
NSLog (@ "olduuid=%@", [[Uidevice Currentdevice] uniqueidentifier]); Unique ID ios5.0 start deprecated
NSLog (@ "name=%@", [[Uidevice Currentdevice] name]); Device Name
NSLog (@ "localizedmodel=%@", [[Uidevice Currentdevice] localizedmodel]); Local mode
NSLog (@ "ios6uuid=%@", [[[[[Uidevice Currentdevice] Identifierforvendor] uuidstring]);//ios6.0 start available

----------Note: The following is not tested and is excerpted 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 already in use
--------------------------------------------------------------------------------------------------------------- --------------
App Info
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:@ "cfbundleshortversionstring"];
App build version
NSString *app_build = [infodictionary objectforkey:@ "cfbundleversion"];

Determine if there is a camera
if ([Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera])
NSLog (@ "there");
Else
NSLog (@ "no");

Six, for different resolutions of the device, programmers only need to do three things:
1. Provide app HD icon;
2.UI picture material @2x.png;
3. Download the appropriate picture from the network (judging conditions [[UIScreen mainscreen] Respondstoselector: @selector (scale)] && [[UIScreen mainscreen] Scale ] = = 2)
-All iphone, IPod Touch Device Point resolution is 320x480, that is, the logical resolution is consistent, to ensure that the app does not need to modify the normal operation in high pixel resolution, but the original app pictures will be pulled up after the display, affecting the beautiful, Did not play the advantage of retina.
-All Gcrectmake in the program are logical resolutions without affecting the location and size! Do game development most useful, ordinary apps have little impact
-Question: How to make relative layout??? (Autoresizemask,autoresizing 6.0 before 6.0 can use AutoLayout similar to Android relative layout)

iOS screen adaptation knowledge

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.