Iphone 如何使用此动画代码?
我是新手,我需要一些帮助 我想在给定的UIView上显示一个弹出图像,但我希望它的行为类似于UIAlertView或Facebook Connect for iPhone模式弹出窗口,因为它有一个弹跳的、像橡皮筋一样的动画 我在网上找到了一些代码,这些代码来自一个试图做类似事情的人。他/她把这些放在一起,但没有演示或说明 因为我是一个新手,所以我不知道如何将它合并到我的代码中 这是我需要显示反弹图像的例程:Iphone 如何使用此动画代码?,iphone,objective-c,cocoa-touch,iphone-sdk-3.0,Iphone,Objective C,Cocoa Touch,Iphone Sdk 3.0,我是新手,我需要一些帮助 我想在给定的UIView上显示一个弹出图像,但我希望它的行为类似于UIAlertView或Facebook Connect for iPhone模式弹出窗口,因为它有一个弹跳的、像橡皮筋一样的动画 我在网上找到了一些代码,这些代码来自一个试图做类似事情的人。他/她把这些放在一起,但没有演示或说明 因为我是一个新手,所以我不知道如何将它合并到我的代码中 这是我需要显示反弹图像的例程: - (void) showProductDetail { . . . /////
- (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];
}
提前感谢您能给我的任何帮助。这很简单。在
showProductDetail
方法中,启动动画块,然后设置\u productDetail.transform
属性,然后提交块。这就是动画发生的原因
您找到的代码旨在制作一系列这样的动画,但正在修改的属性位于self
上,而不是\u productDetail
上。如果\u productDetail
是您自己创建的类的实例,则可以将动画代码放入该类中
否则,只需将
pulse
方法中的代码移动到showProductDetail
方法,并将其他两个方法放在该方法下面。用这三种方法中的\u productDetail.transform
替换self.transform
。如果Felixyz的答案解决了您的问题,您应该接受它。