iOS 适配iPhone X的方法
因为iPhoneX奇特的刘海存在,iOS11之后系统深化了“安全区域”概念,安全区域就是从屏幕上切除最大的矩形之外的区域。
iOS11后UIScrollView新增contentInsetAdjustmentBehavior属性,默认配置UIScrollViewContentInsetAdjustmentAutomatic,效果上就是没使用安全区域。若针对具体页面需要使用安全区域,可以查看API中新增加的那些属性。
/**
*适配iPhoneX的安全区域
*isUse=1表示使用安全区域
*isUse=0表示不使用安全区域
*/
+(void)adaptationSafeAreaWith:(UIScrollView*)svuseArea:(NSInteger)isUse{
if([[svclass]isSubclassOfClass:[UIWebViewclass]]){
UIWebView*webView=(UIWebView*)sv;
for(UIView*aViewin[webViewsubviews]){
if([aViewisKindOfClass:[UIScrollViewclass]]){
sv=(UIScrollView*)aView;
break;
}
}
}
#ifdef__IPHONE_11_0
if([svrespondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]){
if(isUse){
if(@available(iOS11.0,*)){
sv.contentInsetAdjustmentBehavior=UIScrollViewContentInsetAdjustmentNever;
if([[svclass]isSubclassOfClass:[UITableViewclass]]){
UITableView*tv=(UITableView*)sv;
[tvsetInsetsContentViewsToSafeArea:NO];
}
}else{
//Fallbackonearlierversions
}
}else{
if(@available(iOS11.0,*)){
sv.contentInsetAdjustmentBehavior=UIScrollViewContentInsetAdjustmentAlways;
}else{
//Fallbackonearlierversions
}
}
}
#endif
}
typedefNS_ENUM(NSInteger,UIScrollViewContentInsetAdjustmentBehavior){
UIScrollViewContentInsetAdjustmentAutomatic,//Similarto.scrollableAxes,butforbackwardcompatibilitywillalsoadjustthetop&bottomcontentInsetwhenthescrollviewisownedbyaviewcontrollerwithautomaticallyAdjustsScrollViewInsets=YESinsideanavigationcontroller,regardlessofwhetherthescrollviewisscrollable
UIScrollViewContentInsetAdjustmentScrollableAxes,//Edgesforscrollableaxesareadjusted(i.e.,contentSize.width/height>frame.size.width/heightoralwaysBounceHorizontal/Vertical=YES)
UIScrollViewContentInsetAdjustmentNever,//contentInsetisnotadjusted
UIScrollViewContentInsetAdjustmentAlways,//contentInsetisalwaysadjustedbythescrollview'ssafeAreaInsets
}API_AVAILABLE(ios(11.0),tvos(11.0));
以上这篇iOS适配iPhoneX的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下