UIView动画块没有变化

时间:2012-04-28 12:37:43

标签: iphone ios uiview uiviewanimation

以下代码非常简单。 _facebookFUIImageView

if (animationOn == YES) {
    [UIView animateWithDuration:0.4 animations:^{
        [_faceBookF setAlpha:0];
    }];
    [_faceBookF setImage:[UIImage imageNamed:@"facebookFBlue.png"]];
    [UIView animateWithDuration:0.4 animations:^{
        [_faceBookF setAlpha:1];
    }];

     } else {
    [UIView animateWithDuration:0.4 animations:^{
        [_faceBookF setAlpha:0];
    }];
    [_faceBookF setImage:[UIImage imageNamed:@"facebookF.png"]];
        [UIView animateWithDuration:0.4 animations:^{
         [_faceBookF setAlpha:1];
    }];
}

应用程序获取包含此代码的方法,但在整个代码块中不会对UI进行任何更改。据我所知,该应用程序正在主线程上运行。

任何猜测?

更新 - 事实上,问题是图片根本没有改变 - 有或没有动画。这两个图像在应用程序的其他部分都可以正常访问。

3 个答案:

答案 0 :(得分:3)

看起来你正在尝试运行顺序动画,但是你编写它们的方式,它们很可能并行运行。你需要做的是:

if (animationOn == YES) {
    [UIView animateWithDuration:0.4 animations:^{
        [_faceBookF setAlpha:0];
    } completion:^(BOOL finished) {

        [_faceBookF setImage:[UIImage imageNamed:@"facebookFBlue.png"]];
        [UIView animateWithDuration:0.4 animations:^{
           [_faceBookF setAlpha:1];
        }];
    }];



 } 
 else {
   [UIView animateWithDuration:0.4 animations:^{
      [_faceBookF setAlpha:0];
   }completion:^(BOOL finished) {

    [_faceBookF setImage:[UIImage imageNamed:@"facebookF.png"]];
        [UIView animateWithDuration:0.4 animations:^{
         [_faceBookF setAlpha:1];
    }];
 }];
}

答案 1 :(得分:2)

试试这个。这将在第一个动画完成后启动第二个动画。所以它会淡出UIImageView,然后用不同版本的图像淡化它。

 [UIView animateWithDuration: 0.4
                  animations:^
     {
         [_faceBookF setAlpha:0];
     }
                 completion:^(BOOL finished)
     {
         [_faceBookF setImage:[UIImage imageNamed:@"facebookFBlue.png"]];
         [UIView animateWithDuration:0.4
                          animations:^
          {
              [_faceBookF setAlpha:1];
          }];
     }];

答案 2 :(得分:0)

感谢您的回复。我已经实现了你们提到的完成块,以避免同时触发两个动画。但是,主要问题与未正确访问的方法有关。我无法确切地知道原因,因为facebookF变量不是nil,并且方法中的if和log语句运行正常。无论如何,我已经切换到NSNotification解决方案,现在正在访问该方法的所有部分。