Iphone UIView动画块不进行任何更改

Iphone UIView动画块不进行任何更改,iphone,ios,uiview,uiviewanimation,Iphone,Ios,Uiview,Uiviewanimation,下面的代码非常简单\u facebook f是一个ui图像视图 if (animationOn == YES) { [UIView animateWithDuration:0.4 animations:^{ [_faceBookF setAlpha:0]; }]; [_faceBookF setImage:[UIImage imageNamed:@"facebookFBlue.png"]]; [UIView animateWithDuration:

下面的代码非常简单<代码>\u facebook f是一个
ui图像视图

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进行任何更改。据我所知,该应用程序正在主线程上运行

猜猜看


更新——事实上,问题是图像根本没有被改变——不管有没有动画。在应用程序的其他部分可以很好地访问这两个图像。

试试这个。这将在第一个动画完成后开始第二个动画。因此,它将淡出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];
          }];
     }];

试试这个。这将在第一个动画完成后开始第二个动画。因此,它将淡出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];
          }];
     }];

看起来您正在尝试运行连续动画,但按照您编写动画的方式,它们可能会并行运行。您需要做的是:

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];
    }];
 }];
}

看起来您正在尝试运行连续动画,但按照您编写动画的方式,它们可能会并行运行。您需要做的是:

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];
    }];
 }];
}

谢谢你的回复。我已经实现了你们提到的完成块,以避免两个动画同时触发。然而,主要问题与方法没有被正确访问有关。我看不出确切的原因,因为
facebookF
变量不是nil,而且方法中的if和log语句工作正常。无论如何,我已经切换到一个
NSNotification
解决方案,现在该方法的所有部分都被访问了

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

谢谢你的快速回复。我实际上刚刚发现问题的根源是图像没有被改变。要更改的图像位于项目层次结构内,并链接到目标。为什么会这样?也许Interface Builder中的目标并不是您所期望的。确保笔尖链接到正确的UIViewControllerWell,我使用的是故事板,它看起来很好。此外,我遇到问题的相同图像可以在应用程序的其他地方正常访问,这让我认为这是内存问题。正如上面@borrrden所说,请确保UIImageView(_faceBookF)在尝试设置时不是零。感谢您的快速响应。我实际上刚刚发现问题的根源是图像没有被改变。要更改的图像位于项目层次结构内,并链接到目标。为什么会这样?也许Interface Builder中的目标并不是您所期望的。确保笔尖链接到正确的UIViewControllerWell,我使用的是故事板,它看起来很好。此外,我遇到问题的相同图像在应用程序的其他地方也可以正常访问,这让我觉得这是内存问题当您尝试设置图像视图时,它不是nil。可能是在没有注释的情况下被否决的同一个人。您能否确认图像视图在代码中此时不是nil?可能是在没有注释的情况下被否决的同一个人。您能否确认图像视图在代码中此时不是nil?