【发布时间】:2013-04-26 20:42:30
【问题描述】:
我已经使用自定义 UIButton 初始化了 UIBarButtonItem,并将其设置为导航控制器中的 rightBarButtonItem。
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightNavigationButton];//rightNavigationButton is the custom UIButton I set up before
self.navigationItem.rightBarButtonItem = rightBarButtonItem;
通过 UIButton 的外观代理,我设置了 UIControlStates 的颜色(正常/禁用/突出显示)。 UIBarButtonItem 的行为符合预期。
当按下“保存按钮”时,我想突出显示 UIBarButtonItem 以提供已保存内容的视觉反馈。 我要做的是通过在保存动画期间更改标题的颜色来模拟 UIBarButtonItem 的突出显示,因为它似乎不能以编程方式触发突出显示动画(或设置选定的属性)(also mentioned in this post )
所以我所做的是设置一个 IBOutlet 属性,将其连接到 InterfaceBuilder 中的 UIBarButtonItem 并为其分配 rightBarButtonItem。当按下“保存按钮”时,我正在尝试:
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveEaseOut
animations:^{
//some other animation code here
[self.barButtonItemOutlet setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:FONT_ICON size:FONTSIZE],UITextAttributeFont,
HIGHLIGHT_COLOUR,UITextAttributeTextColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 0)],UITextAttributeTextShadowOffset,
[UIColor colorWithRed:0 green:0 blue:0 alpha:0.0],UITextAttributeTextShadowColor,nil]
forState:UIControlStateNormal];
}
completion:nil
];
但是根本没有发生任何事情。我让它以某种方式工作的唯一方法是禁用/启用它。但是由于禁用和突出显示的颜色应该不同,我需要这两种状态,这不是一个真正的选择。
感谢任何帮助!
【问题讨论】:
-
检查是否可以在动画块中将标题的alpha颜色从0更改为1。
-
是的,我可以更改 Alpha 通道。 (Reinhard 还指出这个道具是可动画的)但这对我的变色问题并没有真正的帮助。我错过了什么吗?
标签: ios animation uibutton custom-controls uibarbuttonitem