ARC 中多个 UIImageView 上的 UIView 动画 [英] UIView Animation on multiple UIImageViews in ARC

查看:20
本文介绍了ARC 中多个 UIImageView 上的 UIView 动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有一个动画,它会增长 UIImageView 然后缩小它(实际上是两个动画).在整个应用程序中,这可能发生在几个不同的 UIImageViews 上.我找到了一种非常有效的方法,但它现在似乎与自动引用计数不兼容.这是我的代码:

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

然后:

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

这非常有效,我对此非常满意,直到我尝试将我的项目转换为 ARC.我现在在尝试将 UIImageView 作为动画的上下文传递的这些行中收到错误ARC 不允许将 Objective-C 指针隐式转换为 'void *'":

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

有没有人知道另一种方法可以提醒我希望它作用于哪个 UIImageView 的animationDidStop"函数符合 ARC?

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?

提前非常感谢!

推荐答案

你可以这样做:

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

这篇关于ARC 中多个 UIImageView 上的 UIView 动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆