我是个新手,我需要帮助。
我在网上发现了一些代码,这些代码来自于一个想做类似事情的人。他/她把这些放在一起,但没有演示或说明。
因为我是新手,所以我不知道如何将它合并到我的代码中。
这是我需要弹跳图像出现的例程:
- (void) showProductDetail
{
. . .
////////////////////////////////////////////////////////////////////////
// THIS IS A STRAIGHT SCALE ANIMATION RIGHT NOW. I WANT TO REPLACE THIS
// WITH A BOUNCY RUBBER-BAND ANIMATION
_productDetail.transform = CGAffineTransformMakeScale(0.1,0.1);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
_productDetail.transform = CGAffineTransformMakeScale(1,1);
[UIView commitAnimations];
}
. . .
}这是我找到的代码:
float pulsesteps[3] = { 0.2, 1/15., 1/7.5 };
- (void) pulse {
self.transform = CGAffineTransformMakeScale(0.6, 0.6);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:pulsesteps[0]];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(pulseGrowAnimationDidStop:finished:context:)];
self.transform = CGAffineTransformMakeScale(1.1, 1.1);
[UIView commitAnimations];
}
- (void)pulseGrowAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:pulsesteps[1]];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(pulseShrinkAnimationDidStop:finished:context:)];
self.transform = CGAffineTransformMakeScale(0.9, 0.9);
[UIView commitAnimations];
}
- (void)pulseShrinkAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:pulsesteps[2]];
self.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
}提前感谢你能给我的任何帮助。
发布于 2010-04-04 16:01:58
这相当简单。在showProductDetail方法中,启动一个动画块,然后设置_productDetail.transform属性,然后提交该块。这就是动画发生的原因。
您找到的代码旨在执行一系列这样的动画,但是要修改的属性位于self上,而不是_productDetail上。如果_productDetail是您自己创建的类的实例,则可以将动画代码放入该类中。
否则,只需将pulse方法中的代码移到showProductDetail方法中,并将其他两个方法放在该方法下面。在所有三种方法中,将self.transform替换为_productDetail.transform。
https://stackoverflow.com/questions/2573838
复制相似问题