gpt4 book ai didi

ios - 如何修复推送 VC 后导航栏项目动画到一侧的问题?

转载 作者:行者123 更新时间:2023-11-29 05:38:26 25 4
gpt4 key购买 nike

我有一个 iOS 应用程序,我正在其中为导航项创建自定义 View 。导航项效果很好,每次我来到屏幕时它都会自动定位。

enter image description here但是,当从该屏幕推送 VC 并且我返回到屏幕时,导航项会暂时出现在正确的位置,但会立即转移到右侧角落。

enter image description here

我确实怀疑这与过渡期间导航栏的动画有关,但即使在尝试了多次解决方法之后,它仍然会发生。下面是导航项 View 的代码。

 UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 44)];
v.backgroundColor = [UIColor clearColor];
v.opaque = NO;

UILabel *subtitleLabel = [[UILabel alloc] initWithFrame:CGRectIntegral(CGRectMake(v.bounds.origin.x, v.bounds.origin.y + v.bounds.size.height * 0.6, v.bounds.size.width, v.bounds.size.height * 0.3))];
subtitleLabel.text = subtitle;
subtitleLabel.font = [UIFont systemFontOfSize:11];//Font adjusted to accomodate text into size
subtitleLabel.backgroundColor = [UIColor clearColor];
subtitleLabel.opaque = NO;
subtitleLabel.textAlignment = NSTextAlignmentCenter;
subtitleLabel.textColor = defaultSubtitleTextColor;
subtitleLabel.shadowOffset = defaultShadowOffset;
subtitleLabel.shadowColor = defaultShadowColor;

[v addSubview:subtitleLabel];


UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectIntegral(CGRectMake(v.bounds.origin.x, v.bounds.origin.y + v.bounds.size.height * 0.1, v.bounds.size.width, v.bounds.size.height * 0.5))];
titleLabel.text = title;
titleLabel.font = [UIFont boldSystemFontOfSize:19];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.opaque = NO;
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.textColor = defaultTextColor;
titleLabel.shadowOffset = defaultShadowOffset;
titleLabel.shadowColor = defaultShadowColor;

[v addSubview:titleLabel];

navItem.titleView = v;

已经在这方面花费了大量时间,我们将非常感谢任何帮助。

最佳答案

对于其他处于类似情况的人来说,这与intrinsicContentSize有关。设置后返回UILayoutFittingExpandedSize。问题就消失了。

关于ios - 如何修复推送 VC 后导航栏项目动画到一侧的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56799623/

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