iPhoneX上,当带有tabbar画面跳转到下一个没有tabbar画面时,会发生瞬间的tabbar向上移动的现象,如图:
解决方法是强制设置frame:
swift 3,4
class ActionTabBar: UITabBar {
override var frame: CGRect {
get {
return super.frame
}
set {
var tmp = newValue
if let superview = self.superview, tmp.maxY != superview.frame.height {
tmp.origin.y = superview.frame.height - tmp.height
}
super.frame = tmp
}
}
}
Objective-C
@implementation ActionTabbar
- (void)setFrame:(CGRect)frame
{
if (self.superview && CGRectGetMaxY(self.superview.bounds) != CGRectGetMaxY(frame)) {
frame.origin.y = CGRectGetHeight(self.superview.bounds) - CGRectGetHeight(frame);
}
[super setFrame:frame];
}
@end
本文介绍了一个针对iPhoneX设备上的UITabBar在页面跳转时出现位置偏移现象的问题,并提供了一种通过Swift和Objective-C强制设置frame来解决此问题的方法。
3665

被折叠的 条评论
为什么被折叠?



