日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

iOS開發(fā)retina屏幕下的點與像素關(guān)系詳解_IOS

作者:公眾號iOS逆向 ? 更新時間: 2022-09-18 編程語言

引言

提交app store的時候 需要一張1024*1024的

如果不設(shè)置這兩種的尺寸啟動頁的話,在4英寸、3.5英寸的設(shè)備上展示不了啟動頁,app 的高度也默認(rèn)都是矮的960px.**

注意@3x 提供給開發(fā)的px 為12422208 ,但真實的px 是10801920,系統(tǒng)API會自動進(jìn)行等比例縮?。?/p>

I iOS中點與像素有什么關(guān)系?

  • 點是iOS中標(biāo)準(zhǔn)的坐標(biāo)體系。它就是iOS中的虛擬像素,也被稱為邏輯像素。 在標(biāo)準(zhǔn)設(shè)備中,一個點就是一個像素,但是在Ratina屏幕上,一個點等于2×2個像素。iOS用點作為屏幕的坐標(biāo)測算體系就是為了在Retina設(shè)備和普通設(shè)備上能有一致的視覺效果。
  • 像素是圖片分辨率的尺寸單位。物理像素坐標(biāo)并不會用于屏幕布局,但是仍然和圖片有相對關(guān)系。

retina 屏幕下的點= 像素/2。

II 圖片使用的相關(guān)注意事項

2.1 推薦使用png格式

  • png: 常常放置于Assets.xcassets目錄中,作為控件的背景圖片。

壓縮 較高,無損壓縮,解壓效率高,對CPU消耗少

  • jpg, 常常放置于Supporting Files目錄

1)壓縮比 比較高,通常用于照片、網(wǎng)頁

2)屬于有損壓縮(噪點noise)

3)解壓時對cpu 消耗大--意味著,慢、費(fèi)電

2.2 關(guān)于圖像的實例化

方式一:有緩存加載圖片

       + (UIImage *)imageNamed:(NSString *)name 系統(tǒng)推薦使用的方法,但圖像實例化之后的對象釋放由系統(tǒng)負(fù)責(zé)。
//       [arrayImage addObject: [UIImage imageNamed:pictureNamePrefix]];//參數(shù)為圖片名稱,png 格式的可以不加擴(kuò)展名

方式二:無緩存方式加載圖片(提示、如果放置于Assets.xcassets目錄中的圖片不能使用imageWithContentsOfFile:path進(jìn)行加載;只能使用imageName進(jìn)行加載,即內(nèi)存由系統(tǒng)負(fù)責(zé)了)

//方式二:無緩存方式加載圖片-指定擴(kuò)展名
//        NSArray *arrayPicture = [pictureNamePrefix componentsSeparatedByString:@"."];//從字符中分隔成2個元素的數(shù)組(圖片名+擴(kuò)展名)
//        NSString *path = [[NSBundle mainBundle] pathForResource:arrayPicture[0] ofType: arrayPicture[1]];//獲取圖片的全路徑
        //方式二:無緩存方式加載圖片-不指定擴(kuò)展名
        NSString *path = [[NSBundle mainBundle] pathForResource:pictureNamePrefix ofType:nil];
        [arrayImage addObject:[ UIImage imageWithContentsOfFile:path]];

2.3 動畫結(jié)束之后清除幀動畫數(shù)組

{      //開始動畫
    [self.imageList startAnimating];
    //釋放資源:動畫結(jié)束之后清除幀動畫數(shù)組
    //nvokes a method of the receiver on the current thread using the default mode after a delay.
    [self performSelector:@selector(cleanUpAnimationsArray) withObject:nil afterDelay:self.imageList.animationDuration];//@interface NSObject (NSDelayedPerforming)
}
- (void)cleanUpAnimationsArray{
    NSLog(@"%s ",__func__);
    //動畫結(jié)束之后清除幀動畫數(shù)組
    [self.imageList setAnimationImages:nil];
}

清除內(nèi)存的代碼簡化

 [self.imageList performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.imageList.animationDuration];

III 設(shè)置狀態(tài)欄字體顏色

3.1 方式一

在info.plist中,將View controller-based status bar appearance設(shè)為NO.

在app delegate中:[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

3.2 方式二

VC中重寫 -(UIStatusBarStyle)preferredStatusBarStyle

在viewDidload中調(diào)用:[self setNeedsStatusBarAppearanceUpdate];

但是:當(dāng)vc在nav中時,上面方法沒用,vc中的preferredStatusBarStyle方法根本不用被調(diào)用。

原因是,[self setNeedsStatusBarAppearanceUpdate]發(fā)出后,只會調(diào)用navigation controller中的preferredStatusBarStyle方法,vc中的preferredStatusBarStyley方法跟本不會被調(diào)用。

解決方法:

self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

或者定義一個nav bar的子類,在這個子類中重寫preferredStatusBarStyle方法:

see also

CFBundleAllowMixedLocalizations 開啟系統(tǒng)預(yù)定義的本地化功能

<key>CFBundleAllowMixedLocalizations</key>
 <true/>

原文鏈接:https://juejin.cn/post/7114830492838395911

欄目分類
最近更新