如何使 NavigationItem UIBarButtonItems 在视觉上确认触摸?
我有一个 UINavigationController,我在其中初始化导航栏(使用 MonoTouch):
NavigationBar.BarStyle = UIBarStyle.Black;
NavigationBar.TintColor = UIColor.Black;
在随后推送到导航控制器上的 UIViewController 上,我添加一个按钮:
NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Add, (s, e) => HandleAddItem());
但是,当我触摸按钮时,它不会改变颜色/阴影(即动画)表示它已被触摸。类似的 UIBarButtonItems 添加到另一个视图控制器(普通 UIVIewController)上手动创建的 UINavigationBar 中,动画如我所料。
当导航栏按钮位于已推送到 UINavigationController 上的 UIViewController 上时,如何使导航栏按钮“闪烁”?
I have a UINavigationController where I initialize the NavigationBar as such (using MonoTouch):
NavigationBar.BarStyle = UIBarStyle.Black;
NavigationBar.TintColor = UIColor.Black;
On a UIViewController that I subsequently push onto the navigation controller, I add a button as such:
NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Add, (s, e) => HandleAddItem());
However, when I touch the button, it doesn't change color/shade (i.e. animate) to signify it's been touched. Similar UIBarButtonItems added to a manually-created UINavigationBar on another view controller (plain UIVIewController) animate as I'd expect.
How can I get the navigation bar buttons to "flash" when they are on a UIViewController that has been pushed onto a UINavigationController?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现,一旦更改 UINavigationBar 的
barStyle
和tintColor
,按钮的突出显示状态很可能与默认状态没有什么不同。我相信解决此问题的最佳方法是使用从自定义视图创建的 UIBarButtonItem。这有点痛苦,尤其是当您的按钮使用图像而不是标题时。我绝对建议向 Apple 提交有关此问题的错误报告。
在您的特定情况下,仅将
barStyle
设置为UIBarStyleBlack
并保留tintColor
属性可能会更好。我也很幸运,只指定tintColor
并将barStyle
设置为UIBarStyleDefault
,只要tintColor
是不黑。一般来说,黑色的tintColor
效果不太好。I have found that once you change the UINavigationBar's
barStyle
andtintColor
, there is a very good chance that the highlighted state for the button will be no different than the default state. I believe the best way to work around this is to use a UIBarButtonItem created from a custom view.It's kind of a pain, especially when your button uses an image instead of a title. I would definitely recommend submitting a bug report to Apple about this.
In your particular situation, it might work better to only set the
barStyle
toUIBarStyleBlack
and leave thetintColor
property alone. I have also had luck only specifying thetintColor
and leavingbarStyle
set toUIBarStyleDefault
, as long as thetintColor
is not black. In general, atintColor
of black does not work very well.