如何在UIBarButtonItem上触发高亮效果

Man*_*nni 5 iphone objective-c uibarbuttonitem ios

点击a UIBarButtonItem中的a时UIToolbar,会出现白色发光效果.

是否有可能发射事件以显示此效果?

我不想按下按钮.只应显示效果.我想向用户显示该按钮后面有新内容.

谢谢你的帮助!

Dam*_*sso 2

以下方法假设您正在使用导航控制器的toolbarItems 属性,并且要突出显示的按钮是该数组中的最后一项。当然,您可以将其应用到任何工具栏,并根据需要选择不同的数组索引。

现在这并不完全完美,因为动画将新按钮从屏幕左下角移动。不过,我认为可以通过一点努力将其关闭。

请注意,我使用了 PeakJi 的图像。

我希望这对你有用。

享受,

达米安

- (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];
                     }];
}
Run Code Online (Sandbox Code Playgroud)