如何在iOS上删除UIBarButtonItem tintColor动画?

时间:2017-07-07 07:10:46

标签: ios animation uibarbuttonitem

我在这里有一个BarButtonItem动画:

[UIView animateWithDuration:AnimDurationTintColorHint delay:0 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{
    [view performSelector:@selector(setTintColor:) withObject:UIColor.blackColor];
} completion:^(BOOL finished) {
  ........
}];

因为UIBarButtonItem没有图层属性,所以我无法使用.layer removeAllAnimations来停止分配的无限动画。

如何删除?

1 个答案:

答案 0 :(得分:3)

您必须使用leftBarButtonItem或rightBarButtonItem,然后将UIBarButtonItem的enabled属性设置为NO。

UIImage *img = [UIImage imageNamed:@"your image"];
    UIButton *btnMenu = [UIButton buttonWithType:UIButtonTypeCustom];
    btnMenu.frame = CGRectMake( 10, 0, img.size.width, img.size.height);
    [btnMenu addTarget:self action:@selector(handleBack:) forControlEvents:UIControlEventTouchUpInside];
    [btnMenu setImage:img forState:UIControlStateNormal];
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:btnMenu];
    self.navigationItem.leftBarButtonItem = backButton;
self.navigationItem.leftBarButtonItem.enabled = NO;