iPhone|iPhone X 上tabBar高度有时会变成49的问题
首先我们来看下效果图
文章图片
Untitled.gif 下面是设置代码
文章图片
Snip20180524_1.png 产生这种bug操作顺序是 vc->modal一个控制器->dismiss ->push一个控制器
解决办法:
1、我看了下美团的处理,如下图: Untitled1.gif 美团的是在push一个VC时保证tabBar的高度不变就行,如果测试不觉得是个bug,可以如此。
效果如图:
文章图片
Untitled2.gif 【iPhone|iPhone X 上tabBar高度有时会变成49的问题】代码如下图:
文章图片
Snip20180524_2.png
文章图片
Snip20180524_3.png
首先自定义tabBarVC 在viewWillLayoutSubviews中设置tabBar的frame即可。
下面看下第二种解决办法!!!
2、使用navVC包tabBarVC
效果如图
文章图片
Untitled3.gif
代码如图:
文章图片
Snip20180524_4.png
注意的是:tabBarVC的子控制器不能用nav包住
3、自定义tabBar
@implementation HMTabBar
{
UIEdgeInsets _oldSafeAreaInsets;
}- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_oldSafeAreaInsets = UIEdgeInsetsZero;
}
return self;
}- (void)awakeFromNib {
[super awakeFromNib];
_oldSafeAreaInsets = UIEdgeInsetsZero;
}- (void)safeAreaInsetsDidChange {
[super safeAreaInsetsDidChange];
if (!UIEdgeInsetsEqualToEdgeInsets(_oldSafeAreaInsets, self.safeAreaInsets)) {
[self invalidateIntrinsicContentSize];
if (self.superview) {
[self.superview setNeedsLayout];
[self.superview layoutSubviews];
}
}
}- (CGSize)sizeThatFits:(CGSize)size {
size = [super sizeThatFits:size];
if (@available(iOS 11.0, *)) {
float bottomInset = self.safeAreaInsets.bottom;
if (bottomInset > 0 && size.height < 50 && (size.height + bottomInset < 90)) {
size.height += bottomInset;
}
}return size;
}- (void)setFrame:(CGRect)frame {
if (self.superview) {
if (frame.origin.y + frame.size.height != self.superview.frame.size.height) {
frame.origin.y = self.superview.frame.size.height - frame.size.height;
}
}
[super setFrame:frame];
}@end
#import "HMTabBarVC.h"
#import "HMTabBar.h"#define kTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height>20?83:49)@interface HMTabBarVC ()@end@implementation HMTabBarVC- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.HMTabBar *tabBar = [[HMTabBar alloc] init];
[self setValue:tabBar forKey:@"tabBar"];
}//- (void)viewWillAppear:(BOOL)animated {
//[super viewWillAppear:animated];
//[self.navigationController setNavigationBarHidden:YES animated:YES];
//}//- (void)viewWillLayoutSubviews {
//[super viewWillLayoutSubviews];
//
//self.tabBar.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height - kTabBarHeight, [UIScreen mainScreen].bounds.size.width, kTabBarHeight);
//
//}@end
参考:https://www.jianshu.com/p/35922343281b
推荐阅读
- Y房东的后半生14
- 陇上秋二|陇上秋二 罗敷媚
- MediaRecorder前后摄像头同时录像
- live|live to inspire 一个普通上班族的流水账0723
- 上班后阅读开始变成一件奢侈的事
- 危险也是机会
- “精神病患者”的角度问题
- 亲子日记第186篇,2018、7、26、星期四、晴
- 海院(实干是海院风景(上))
- 带有Hilt的Android上的依赖注入