我有一个UIImageView添加为子视图。我正在尝试使用transform对其进行动画处理。动画没有,但是imageview是正确缩放的,只是不能自动反转。难道我做错了什么?

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

关于ios - 动画无法在UIImageView上运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34363248/

10-10 08:48
查看更多