gpt4 book ai didi

ios - 为什么页面推送动画 Tabbar 在 iPhone X 上移

转载 作者:IT王子 更新时间:2023-10-29 07:47:47 25 4
gpt4 key购买 nike

我构建了一个应用程序 Demo,使用 hidesBottomBarWhenPushed 在推送动画中隐藏 Tabbar。

Page Relationship

但是,当我点击跳转按钮时,Tabbar 会向上移动!?像这样: Tabbar Move up

最佳答案

VoidLess 提供的答案仅部分修复了 TabBar 问题。它修复了标签栏内的布局问题,但是如果您使用隐藏标签栏的 View Controller ,则标签栏在动画期间呈现不正确(要重现它最好有 2 个 segues - 一个模态和一个推送。如果你交替 segues,你可以看到 tabbar被渲染错位)。请参阅下面解决这两个问题的代码。干得好,苹果。

class SafeAreaFixTabBar: UITabBar {

var oldSafeAreaInsets = UIEdgeInsets.zero

@available(iOS 11.0, *)
override func safeAreaInsetsDidChange() {
super.safeAreaInsetsDidChange()

if oldSafeAreaInsets != safeAreaInsets {
oldSafeAreaInsets = safeAreaInsets

invalidateIntrinsicContentSize()
superview?.setNeedsLayout()
superview?.layoutSubviews()
}
}

override func sizeThatFits(_ size: CGSize) -> CGSize {
var size = super.sizeThatFits(size)
if #available(iOS 11.0, *) {
let bottomInset = safeAreaInsets.bottom
if bottomInset > 0 && size.height < 50 && (size.height + bottomInset < 90) {
size.height += bottomInset
}
}
return size
}

override var frame: CGRect {
get {
return super.frame
}
set {
var tmp = newValue
if let superview = superview, tmp.maxY !=
superview.frame.height {
tmp.origin.y = superview.frame.height - tmp.height
}

super.frame = tmp
}
}
}
}

objective-c 代码:

@implementation VSTabBarFix {
UIEdgeInsets oldSafeAreaInsets;
}


- (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

关于ios - 为什么页面推送动画 Tabbar 在 iPhone X 上移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46232929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com