如何在UIBarButtonItem上激发高光效果 [英] How to fire hightlight effect on UIBarButtonItem
问题描述
当您点击 UIToolbar
中的 UIBarButtonItem
时,会出现白色发光效果.
When you tap on a UIBarButtonItem
in a UIToolbar
, there is a white glow effect.
是否可以触发一个事件来显示这种效果?
我不想按按钮.仅应显示效果.我想向用户显示,此按钮后面有新内容.
I don't want to press the button. Only the effect should be displayed. I want to visualize to the user, that there is new content behind this button.
感谢您的帮助!
推荐答案
以下方法假定您正在使用导航控制器的toolbarItems属性,并且要突出显示的按钮是该数组中的最后一项.当然,您可以将其应用于任何工具栏,并在必要时选择其他数组索引.
The following method assumes you are using the toolbarItems property of a navigation controller and that the button you want to highlight is the last item in that array. You can apply it to any toolbar, of course, and pick a different array index if necessary.
现在这还不是很完美,因为动画从屏幕的左下角移动了新按钮.但是,我认为可以通过一点努力将其关闭.
Right now this is not exactly perfect, because the animation moves the new button from the lower left of the screen. However, I think that can be turned off with a little effort.
请注意,我使用了PeakJi的图像.
Note that I used PeakJi's image.
我希望这对您有用.
享受,
达明(Damien)
- (void)highlightButton {
NSArray *originalFooterItems = self.toolbarItems;
NSMutableArray *footerItems = [originalFooterItems mutableCopy];
[footerItems removeLastObject];
NSString* pathToImageFile = [[NSBundle mainBundle] pathForResource:@"white_glow" ofType:@"png"];
UIImage* anImage = [UIImage imageWithContentsOfFile:pathToImageFile];
UIImageView *imageView = [[UIImageView alloc] initWithImage:anImage];
imageView.frame = CGRectMake(0, 0, 40, 40);
UIBarButtonItem *flashImage = [[UIBarButtonItem alloc] initWithCustomView:imageView];
[footerItems addObject:flashImage];
[UIView animateWithDuration:0.3
delay: 0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
self.toolbarItems = footerItems; }
completion:^(BOOL finished){
[UIView animateWithDuration:.3
delay: 0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
self.toolbarItems = originalFooterItems;
}
completion:nil];
}];
}
这篇关于如何在UIBarButtonItem上激发高光效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!