动画不适用于 UIImageView

Animation not working on UIImageView

我添加了一个 UIImageView 作为子视图。我正在尝试使用变换对其进行动画处理。动画没有,但是图像视图已正确缩放,只是没有自动反转。我做错了什么吗?

UIImageView * iv_tap = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gesture_tap"]];
    iv_tap.center = point;
    iv_tap.tag = 779;
    iv_tap.hidden = true;
    [UIView animateWithDuration:2.0
                          delay:.05
                        options: UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear
                     animations:^{
                         iv_tap.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.8, 1.8);
                     }
                     completion:NULL];


    [self addSubview:iv_tap];

imageView添加到view后需要做动画。如果您在 addSubView 之前执行动画,则图像视图不在视图层次结构中,您看不到任何动画。

 UIImageView * iv_tap = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gesture_tap"]];
[self.view addSubview:iv_tap];   //this could be self in your case
iv_tap.tag = 779; 

[UIView animateWithDuration:2.0 delay:0.05  options:UIViewAnimationOptionCurveEaseOut animations:^{

    iv_tap.center=self.view.center;
    iv_tap.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.8, 1.8);

    [self.view layoutIfNeeded];    //this could be self in your case

} completion:^(BOOL finished) {
        //do your stuff when animation is done
}];

如果你是 UIView 的子类,那么你甚至可以把它放在 drawRect 方法中:

UIImageView * iv_tap = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gesture_tap"]];
[self addSubview:iv_tap];   
iv_tap.tag = 779;

[UIView animateWithDuration:2.0 delay:0.05  options:UIViewAnimationOptionCurveEaseOut animations:^{

    iv_tap.center=self.center;
    iv_tap.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.8, 1.8);

    [self layoutIfNeeded];   

} completion:^(BOOL finished) {
        //do your stuff when animation is done
 }];