如何对导航项进行动画处理(闪烁或闪烁)



我有一个scrollView应用程序。每个滚动视图项目都有自己的标题(导航项目标题)。现在,当用户对特定的scrollView项目执行某些操作(我有办法捕获此事件)时,我想对导航项进行动画处理。

我在想也许连续改变它的背景颜色或其他东西,或者如果可能的话,可以更好地增加/减少它的透明度。

有没有人做过类似的事情?这样做的正确方法是什么?我没有脚本要求我需要做什么,只是当前的 scrollView 项目(视图)与其他项目不同。

感谢您的任何建议

我从收到的回复中得到了它:

CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"opacity"];
    animation.duration=1.5;
    animation.repeatCount=1000000;
    animation.autoreverses=YES;
    animation.fromValue=[NSNumber numberWithFloat:1.0];
    animation.toValue=[NSNumber numberWithFloat:0.3];
    [button addAnimation:animation forKey:@"animateOpacity"];

我希望它不会太快和太密集导致癫痫发作

UIBarButtonItem(令人讨厌)不会继承自UIView,所以如果你尝试的话,CoreAnimation会做蹲下。 但是,如果您滚动自己的导航项,并将UIButtonUIImageView设置为customView属性,则完全可以使用UIView的块动画包装器进行动画:

[UIView animateWithDuration:1.0f animations:^{
    [myButton setAlpha:0.0f];
    //the button is now invisible
}];

至于彩色动画,不幸的是,只有CGColors可以动画化,然后,只有在非常粗略的情况下。

您可以执行以下操作,而不是尝试对整个按钮进行动画处理。对于导航项目的闪烁或闪烁动画,您只需更改其色调颜色

  // call timer where you want to start the blinking or flash like animation
 [NSTimer scheduledTimerWithTimeInterval:0.65f target:self selector:@selector(animate) userInfo:nil repeats:YES];

 -(void)animate
  {
   if (flagAnimate == 0) {
   self.navigationItem.leftBarButtonItem.tintColor = [UIColor redColor];
     flagAnimate = 1;
  }
   else if (flagAnimate == 1)
  {
 self.navigationItem.leftBarButtonItem.tintColor = [UIColor grayColor];
     flagAnimate = 0;
  }

最新更新