2010-04-04 94 views
0

我是一个新手,我需要一些帮助。如何使用此动画代码?

我想在给定的UIView上显示一个弹出图像,但是我希望它的行为像UIAlertView或者像Facebook Connect for iPhone模式弹出窗口一样,因为它有一个弹性的,橡皮筋状的动画到它。

我在网上找到了一些正在尝试做类似事情的人的代码。他/她把这些放在一起,但没有演示或说明。

因为我是如此的新,我不知道如何将其纳入我的代码。

这是我需要有弹性的形象出现在常规:

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

在此先感谢您的帮助,您可以给我。

+0

你应该接受Felixyz的答案,如果它解决了你的问题。 – neha 2011-03-02 11:06:25

回答

2

这很简单。在你的showProductDetail方法中,你启动一个动画块,然后设置_productDetail.transform属性,然后提交该块。这就是动画发生的原因。

您找到的代码旨在执行此类动画链,但要修改的属性是self而不是_productDetail。如果_productDetail是您自己创建的类的实例,则可以将该动画代码放入该类中。否则,只需将pulse方法中的代码移动到showProductDetail方法,然后将其他两个方法放在该方法的下面即可。在所有三种方法中将self.transform替换为_productDetail.transform