uibutton动画

问题描述:

有没有可能通过这种方式为uibutton创建动画,例如背景中出现的东西或任何东西,例如麦穗从田地里出来。uibutton动画

这是可能的吗?

谢谢:)

+0

因此,您希望麦穗是按钮,并且该领域是背景图像? – Ned 2011-03-16 19:02:44

+0

是的,这是正确的:) – Leon 2011-03-16 19:37:26

除非你想要一个更复杂的动画,你可以创建一个自定义类型的UIButton(通过改变类型的自定义或者与IB或编程方式与UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom]),然后设置按钮的图像与[aButton setImage:[UIImage imageNamed:@"wheat_ear" forState:UIControlStateNormal]

要移动它,只是动画的位置通常...

[UIView animateWithDuration:0.5 animations:^{aButton.center = newCenter;}]; 

或者提供它的现身现场的假象,动画图像的边界,使其与图像的开始宽度和零高度,并以图像的宽度和高度结束:

CGRect originalFrame = aButton.frame; 
aButton.frame = CGRectMake(originalFrame.origin.x, originalFrame.origin.y, originalFrame.size.width, 0); 
[UIView animateWithDuration:0.5 animations:^{aButton.frame = originalFrame;}]; 
+0

你能给我举一个你最后描述的部分的例子吗? (从图像的宽度和零高开始,以图像的宽度和高度结束)。 – Leon 2011-03-16 20:29:08

+0

添加到我的答案下面。 – Ned 2011-03-17 14:40:31

+0

这是非常有帮助的,但是当我试图将其作为书面材料使用时出现错误。我需要设置原点和宽度:aButton.frame = CGRectMake(originalFrame.origin.x,originalFrame.origin.y,originalFrame.size.width,0); – DenVog 2012-06-18 20:59:19