设置UIView动画的初始值

时间:2013-09-21 14:57:01

标签: ios uiview uiimageview uiviewanimation

我在触发滑动事件时运行此代码,它显示一个箭头在淡出时放大,因为您看到我将图像的位置设置为与滑动位置相同的位置,但它仅从前一次触摸的位置(在完成块中设置)。但是在方法开始时我设置了更新位置,为什么它会从上一次触摸的位置动画?

    static bool isAnimating;
- (void)animateImageZoom: (UIImageView *)imageView startingAtLocation:(CGPoint)location inDirection: (FadeDirection)direction
{
    if (!isAnimating) {
        CGRect previousFrame = imageView.frame;
        imageView.frame = CGRectMake(location.x, location.y, previousFrame.size.width, previousFrame.size.height);
        imageView.hidden = NO;


        [UIView animateWithDuration:0.6f
                              delay:0.3f
                            options:UIViewAnimationOptionBeginFromCurrentState
                         animations:^(void) {
                             isAnimating = YES;
                             imageView.alpha = 0;

                             // ZOOM
                             if (direction == fadeLeft) {
                                 imageView.frame = CGRectMake(location.x,
                                                              location.y, 256, 256);
                             } else if (direction == fadeRight) {
                                 imageView.frame = CGRectMake(location.x,
                                                              location.y, 256, 256);
                             }
                         }
                         completion:^(BOOL finished) {
                             isAnimating = NO;

                             imageView.frame = CGRectMake(location.x, location.y, previousFrame.size.width, previousFrame.size.height);
                             imageView.hidden = YES;
                             imageView.alpha = 0.8f;
                         }];
    }
}

0 个答案:

没有答案