您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)iOS如何適配iPhone X,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
因?yàn)閕Phone X奇特的劉海存在,iOS11之后系統(tǒng)深化了“安全區(qū)域”概念,安全區(qū)域就是從屏幕上切除最大的矩形之外的區(qū)域。
iOS11后UIScrollView新增contentInsetAdjustmentBehavior屬性,默認(rèn)配置UIScrollViewContentInsetAdjustmentAutomatic,效果上就是沒(méi)使用安全區(qū)域。若針對(duì)具體頁(yè)面需要使用安全區(qū)域,可以查看API中新增加的那些屬性。
/** * 適配iPhone X的安全區(qū)域 * isUse = 1 表示使用安全區(qū)域 * isUse = 0 表示不使用安全區(qū)域 */ + (void)adaptationSafeAreaWith:(UIScrollView *)sv useArea:(NSInteger)isUse { if ([[sv class] isSubclassOfClass:[UIWebView class]]) { UIWebView *webView = (UIWebView *)sv; for (UIView *aView in [webView subviews]) { if ([aView isKindOfClass:[UIScrollView class]]) { sv = (UIScrollView *)aView; break; } } } #ifdef __IPHONE_11_0 if ([sv respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) { if (isUse) { if (@available(iOS 11.0, *)) { sv.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; if ([[sv class] isSubclassOfClass:[UITableView class]]) { UITableView *tv = (UITableView *)sv; [tv setInsetsContentViewsToSafeArea:NO]; } } else { // Fallback on earlier versions } } else { if (@available(iOS 11.0, *)) { sv.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways; } else { // Fallback on earlier versions } } } #endif }
typedef NS_ENUM(NSInteger, UIScrollViewContentInsetAdjustmentBehavior) { UIScrollViewContentInsetAdjustmentAutomatic, // Similar to .scrollableAxes, but for backward compatibility will also adjust the top & bottom contentInset when the scroll view is owned by a view controller with automaticallyAdjustsScrollViewInsets = YES inside a navigation controller, regardless of whether the scroll view is scrollable UIScrollViewContentInsetAdjustmentScrollableAxes, // Edges for scrollable axes are adjusted (i.e., contentSize.width/height > frame.size.width/height or alwaysBounceHorizontal/Vertical = YES) UIScrollViewContentInsetAdjustmentNever, // contentInset is not adjusted UIScrollViewContentInsetAdjustmentAlways, // contentInset is always adjusted by the scroll view's safeAreaInsets } API_AVAILABLE(ios(11.0),tvos(11.0));
關(guān)于“iOS如何適配iPhone X”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。