Xcode Release版本出來了恒水,iPhone的適配也在悄然進(jìn)行中。此篇文章就此針對(duì)iPhone X的UITabBar
做適配顷蟆。
UITabBar 偏移問題
當(dāng)在push到下一界面時(shí)诫隅,并設(shè)置hidesBottomBarWhenPushed
為YES
將會(huì)出現(xiàn)Figure-1
的情況 -- UITabBar
向上偏移34pt
即藍(lán)色區(qū)域。下面提供一個(gè)safeAreaInsets
變化的過程:
deltaVaue = 83 - 49 = 34
2017-09-21 15:32:50.063642+0800 ios11NavBar[3698:126162] viewSafeAreaInsetsDidChange:{44, 0, 83, 0}
2017-09-21 15:32:50.070815+0800 ios11NavBar[3698:126162] DidLayout-containerView: {{0, 0}, {375, 812}}
2017-09-21 15:32:56.447208+0800 ios11NavBar[3698:126162] viewSafeAreaInsetsDidChange:{44, 0, 49, 0}
2017-09-21 15:32:56.447649+0800 ios11NavBar[3698:126162] DidLayout-containerView: {{0, 0}, {375, 778}}
2017-09-21 15:32:56.448666+0800 ios11NavBar[3698:126162] viewSafeAreaInsetsDidChange:{44, 0, 83, 0}
2017-09-21 15:32:56.448890+0800 ios11NavBar[3698:126162] DidLayout-containerView: {{0, 0}, {375, 812}}
Figure-1
解決方案
繼承UITabBarController
帐偎,修改UITabBar
的Y
坐標(biāo)值逐纬。不是最優(yōu)方案,如果有較好的方案希望大家能不嗇指點(diǎn)一二削樊。
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
//TODO: adapt tabbar's y value.
if ([RTDeviceHardware iPhoneXDevice]) {
CGFloat deltaTabBarY = SCREEN_HEIGHT - CGRectGetHeight(self.tabBar.frame);
self.tabBar.frame = (CGRect){0, deltaTabBarY, self.tabBar.bounds.size};
}
}
最終效果如圖
Figure-2
UITableView 刷新后偏移問題
在iOS11上豁生,設(shè)置UITableView
的style
為UITableViewStyleGrouped
時(shí)兔毒,并且行高大于220(囧 項(xiàng)目中有類似問題,又經(jīng)過反復(fù)驗(yàn)證我就大膽預(yù)估了一個(gè)值甸箱,220就由此得來)育叁,當(dāng)push再pop回來刷新列表 就會(huì)導(dǎo)致列表偏移,并沒有停留在之前的位置芍殖。
Figure-3
解決方案
//TODO: iOS 11之后豪嗽,預(yù)估值有默認(rèn)高度,如果不需要就設(shè)置0
_tableView.estimatedRowHeight = 0;//這里需要吐槽下豌骏,如果不設(shè)置為0 就會(huì)出現(xiàn)刷新后偏移問題龟梦。
_tableView.estimatedSectionHeaderHeight = 0;
_tableView.estimatedSectionFooterHeight = 0;