1、旋轉處理
第一步:註冊通知 [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(changeFrames:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
第二把:處理接收事件
-(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);
}
2、獲取屏幕分辨率
//獲得當前屏幕的尺寸:
CGSize size_screen = [[UIScreenmainScreen]bounds].size;
//得到縮放率:
CGFloat scale_screen = [UIScreen mainScreen].scale;
此時屏幕尺寸的寬高與scale的乘積就是相應的分辨率值。
CGRect sizeOfA4 = CGRectMake(0, 0, 595, 842);//生成PDF文件時按A4標準
CGRect sizeOfA5 = CGRectMake(0, 0, 421, 595);//生成PDF文件時按A5標準
注意:無論scale=1仍是scale=2,紙張的標準sizeOfA4和sizeOfA5的設置都不變,這是由於咱們一般設置的寬高在iOS體系下都是邏輯上的point,並非真實的像素!
只要屏幕是等比例放大縮小,[[UIScreenmainScreen]bounds].size都不變。不一樣scale的系統會自動放大或縮小,這就是全部的應用在320x480和640x960環境下無差異運行的緣由。
3、設備標準
iPhone/iPod Touch (320點 x 480點)
普屏分辨率 320像素 x 480像素
Retina分辨率 640像素 x 960像素
iPad,iPad2/New iPad (768點 x 1024點)
普屏 768像素 x 1024像素
Retina屏 1536像素 x 2048像素
換算關係 (在 iPhone3 上 1個 Point 至關於 1個pixel ; 而 iPhone4 上1個 point 就至關於4個 pixel;)
普屏 1點 = 1像素 image.png
Retina屏 1點 = 2像素 image@2x.png html
4、 真機與模擬器判斷+設備類型判斷
#if defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR
NSLog(@" on simulator");
#else
NSLog(@"not on simulator");
#endif
注意:TARGET_OS_IPHONE在真機和模擬器上都是1
設備類型判斷方法有兩種:
1. UI_USER_INTERFACE_IDIOM() 進行區分(ios 3.2以上),可是沒法區分iphone和ipod
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//設備爲ipad
} else {
//設備爲iphone 或 ipod
}
2. 使用 UIDevice.model 進行區分 (ios 2.0 >=)
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:@"iPhone"]) {
//iPhone
}else if([deviceType isEqualToString:@"iPod touch"]) {
//iPod Touch
}else {
//iPad
}android
5、獲取設備相關信息
//軟件信息
NSLog(@"sysname=%@",[[UIDevice currentDevice] systemName]);// 系統名
NSLog(@"systemVersion=%@",[[UIDevice currentDevice] systemVersion]); //版本號
NSLog(@"model=%@",[[UIDevice currentDevice] model]); //類型(ipad、ipod、iphone)而[[UIDevice currentDevice] userInterfaceIdiom]只能判斷iphone和ipad
NSLog(@"olduuid=%@",[[UIDevice currentDevice] uniqueIdentifier]); //惟一識別碼 ios5.0開始deprecated
NSLog(@"name=%@",[[UIDevice currentDevice] name]); //設備名稱
NSLog(@"localizedModel=%@",[[UIDevice currentDevice] localizedModel]); // 本地模式
NSLog(@"ios6UUID=%@",[[[UIDevice currentDevice] identifierForVendor] UUIDString]);//ios6.0開始available
----------注:如下內容未測試,摘自http://www.cnblogs.com/mrhgw/archive/2012/06/27/2565798.html---------------
// 硬件信息
[UIDevice platform];//平臺
[UIDevice cpuFrequency]];//cpu信息
UIDevice busFrequency]];//總線
[UIDevice totalMemory]];//總內存
UIDevice userMemory]];//已經使用的內存
-----------------------------------------------------------------------------------------------------------------------------
//App信息
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
CFShow(infoDictionary);//全部plist內容
// app名稱
NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
// app版本
NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
// app build版本
NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];ios
判斷是否有照相機
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
NSLog(@"有");
else
NSLog(@"沒有");程序員
6、針對不一樣分辨率的設備,程序員只須要作三件事:
1.提供app高清圖標;
2.UI圖片素材@2x.png;
3.從網絡下載適配的圖片(判斷條件[[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2)
-全部的iPhone、iPod Touch設備的 Point分辨率都是 320×480,也就是邏輯分辨率都一致,保證了App不須要修改也能正常的在高像素分辨率上運行,只是原來App中的圖片會被拉昇後顯示,影響美觀,沒有發揮retina的優點。
-程序內全部的GCRectMake都是邏輯分辨率,不影響位置和大小!作遊戲開發最有用,普通app影響不大
-問題:如何進行相對佈局???(6.0以前有autoResizeMask,autoresizing 6.0可以使用與android相對佈局相似的autoLayout)網絡