UIView Animation on multiple UIImageViews in ARC

不羁岁月 提交于 2019-12-02 20:52:31

问题


I have an animation in my app that grows a UIImageView and then shrinks it (really two animations). Throughout the app this may happen on several different UIImageViews. I found a way to do this that worked really well, but it now doesn't seem to be compatible with Automatic Reference Counting. Here is my code:

[UIView beginAnimations:@"growImage" context:imageName];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDelegate:self];
imageName.transform = CGAffineTransformMakeScale(1.2, 1.2);
[UIView commitAnimations];

and then:

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(UIImageView *)context {
    if (animationID == @"growImage") {
    [UIView beginAnimations:@"shrinkImage" context:context];
    [UIView setAnimationDuration:0.5f];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDelegate:self];
    context.transform = CGAffineTransformMakeScale(0.01, 0.01);
    [UIView commitAnimations];
    }
}

This worked perfectly and I was very happy with it, until I tried converting my project to ARC. I now get the error "Implicit conversion of an Objective-C pointer to 'void *' is disallowed with ARC" on these lines in which I try to pass a UIImageView as the context for the animation:

[UIView beginAnimations:@"growImage" context:imageName];
[UIView beginAnimations:@"shrinkImage" context:context];

Does anybody know of another way that I can alert the "animationDidStop" function of which UIImageView I want it to act on that would be compliant with ARC?

Thanks so much in advance!


回答1:


You can do as follows:

[UIView beginAnimations:@"growImage"
                context:(__bridge void*)imageName];
imageName.transform = ...
[UIView commitAnimations];



回答2:


Any reason you are not using the much simpler block based animation?

[UIView animateWithDuration:0.5 animation:^{
    imageName.transform = CGAffineTransformMakeScale(1.2, 1.2);
} completion ^(BOOL finished) {
    [UIView animateWithDuration:0.5 animation:^{
        imageName.transform = CGAffineTransformMakeScale(0.01, 0.01);
    }];
}];


来源:https://stackoverflow.com/questions/8157105/uiview-animation-on-multiple-uiimageviews-in-arc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!