0

我在使用滑块触发一系列动画时遇到问题,代码如下:

-(void)slideAlpha:(id)sender{

  self.bigPhotoViewA.alpha = self.alphaSlider.value;

  if (self.alphaSlider.value == 1){

    [UIView animateWithDuration:1
                     animations:^{
                         self.alphaSlider.alpha = 0;
                     } completion:nil
    ];

    [self performSelector:@selector(nextPhotoAnimation) withObject:self afterDelay:5.0 ];
  }
}

-(void) nextPhotoAnimation{

  self.alphaSlider.value = 0;

  [UIView animateWithDuration:2
                   animations:^{
                       self.bigPhotoViewA.alpha = 0.0;
                       self.bigPhotoView.alpha = 0.0;
                       self.smallPhotoView.center = CGPointMake(startX, startY);
                   }
                   completion:^(BOOL finished) {
                       NSLog(@"Animation ended");
                       self.smallPhotoView.image = ((UIImage *)[smallImagesArray objectAtIndex:imageCount]);
                   }
  ];
}

因此,当滑块达到值 1 时,nextPhotoAnimation会在延迟后启动。到目前为止,一切都很好。问题来了nextPhotoAnimation。该animations块运行正常,但每次调用该completion块都会运行多次。nextPhotoAnimation启动时NSLog显示 6 到 9 次nextPhotoAnimation,然后在 2 秒后在正确的时间再次显示。

NSLog

我试图用更简单的代码来复制这个问题,并且animation/completion流工作得很好。

4

2 回答 2

1

试试这个nextPhotoAnimation

-(void) nextPhotoAnimation{

    self.alphaSlider.value = 0;

    [UIView animateWithDuration:2
               animations:^{
                   self.bigPhotoViewA.alpha = 0.0;
                   self.bigPhotoView.alpha = 0.0;
                   self.smallPhotoView.center = CGPointMake(startX, startY);
               }
               completion:^(BOOL finished) {
                   if (finished) {
                       NSLog(@"Animation ended");
                       self.smallPhotoView.image = ((UIImage *)[smallImagesArray objectAtIndex:imageCount]);
                   }
               }
    ];
}
于 2014-01-30T10:18:09.673 回答
0

你也没有使用

[UIView beginAnimations:nil context:nil];

也不

[UIView 提交动画]; 最好的方法是创建一个 UIView,然后使用协议。使用 [self YOURMETHOD] 调用你的方法;在视图中。:-)

于 2014-01-30T10:29:00.847 回答