首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用此动画代码?

如何使用此动画代码?
EN

Stack Overflow用户
提问于 2010-04-04 15:37:36
回答 1查看 740关注 0票数 0

我是个新手,我需要帮助。

我在网上发现了一些代码,这些代码来自于一个想做类似事情的人。他/她把这些放在一起,但没有演示或说明。

因为我是新手,所以我不知道如何将它合并到我的代码中。

这是我需要弹跳图像出现的例程:

代码语言:javascript
复制
- (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];      
    }
. . .
}

这是我找到的代码:

代码语言:javascript
复制
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];
}

提前感谢你能给我的任何帮助。

EN

回答 1

Stack Overflow用户

发布于 2010-04-04 16:01:58

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

您找到的代码旨在执行一系列这样的动画,但是要修改的属性位于self上,而不是_productDetail上。如果_productDetail是您自己创建的类的实例,则可以将动画代码放入该类中。

否则,只需将pulse方法中的代码移到showProductDetail方法中,并将其他两个方法放在该方法下面。在所有三种方法中,将self.transform替换为_productDetail.transform

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2573838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档