每次重绘时都会重新应用 UIBarButtonItem 图像插入?

发布于 2025-01-01 05:32:38 字数 527 浏览 2 评论 0原文

我有一个 UIToolbar 作为我的 UINavigationController 的一部分。 UIToolbar 上有几个普通的 UIBarButtonItem,每个都有我在界面生成器中指定的自定义图像。我的图像并不像我想要的那样居中,因此我在尺寸检查器的顶部应用了一个小图像插图。

UIToolbar

左边的按钮没有内嵌,右边的按钮在 6 的上方有一个内嵌。

但是,似乎每当重新绘制工具栏时(从模态视图返回后,或隐藏和取消隐藏工具栏),带有插图的按钮就会越来越小,就像插图每次都被重新应用一样。所以它看起来像这样:

Messed up UIToolbarButtonItem

这是 iOS 中的错误,还是我做错了什么?

先感谢您。

I have a UIToolbar as part of my UINavigationController. The UIToolbar has several plain UIBarButtonItems on it, each with custom images I specified in interface builder. My images don't fit quite as centered as I'd like, so I apply a small image inset to the top in the size inspector.

UIToolbar

The button on the left has no inset, and the one on the right has an inset on the top of 6.

However, it seems that whenever the toolbar is redrawn (after coming back from a modal view, or hiding and unhiding the toolbar), the button with an inset shrinks more and more—like the inset is getting reapplied every time. So it looks like this:

Messed up UIToolbarButtonItem

Is this a bug in iOS, or am I doing something wrong?

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

身边 2025-01-08 05:32:38

我在使用 iPhone 应用程序时遇到了同样的问题,特别是从模态视图返回时。我处理它的方法是在模态被解雇时触发 NSNotification,有问题的视图会听取。有点像这样。

[[NSNotificationCenter defaultCenter]postNotificationName:@"DismissingModal" object:nil];

然后将其注册到您的其他类中以触发您的方法。

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(drawRect:) name:@"DismissingModal" object:nil];

I had this same problem with an iPhone app specifically when returning from a modal view. The way I handled it was to fire off an NSNotification when the Modal is being dismissed that the views which were having issues would listen to. Kinda Like this.

[[NSNotificationCenter defaultCenter]postNotificationName:@"DismissingModal" object:nil];

Then register it in your other class to fire your method.

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(drawRect:) name:@"DismissingModal" object:nil];
心凉 2025-01-08 05:32:38

您什么时候调整图像的插图?如果您在 ViewWillAppear (或 ViewDidAppear)中执行此操作,则当模式被关闭时,该方法将被再次调用。

也许你可以在 ViewDidLoad 中进行插入调整?

When are you adjusting the inset for your image? If you are doing it in ViewWillAppear (or ViewDidAppear), that method is being called again when the modal is being dismissed.

Perhaps you can make the inset adjustment in ViewDidLoad instead?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文