动画:如何在加载视图时使UI按钮从右向左移动?

时间:2009-11-04 06:15:33

标签: iphone animation

到目前为止,我还没有完成iphone开发的任何动画。

任何人都可以帮助我在加载视图时如何让UI按钮从右向左移动?

我希望产生这样的效果:当加载视图时,按钮显示从右端到左移动&停在它的位置。有可能吗?

对此动画内容的任何帮助表示赞赏。如果有的话,请提供一些样本帮助。

提前致谢。

4 个答案:

答案 0 :(得分:32)

为了让它更加流畅,我建议不要改变UIView的框架,而是要改变它的中心;

CGPoint newLeftCenter = CGPointMake( 20.0f + myButton.frame.size.width / 2.0f, myButton.center.y);
[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:1.0f];
myButton.center = newLeftCenter;
[UIView commitAnimations];

答案 1 :(得分:2)

在viewDidAppear:(BOOL)动画方法中,您可以在动画块中更改按钮的帧。所以你会看到你想要的东西。检查UIView类引用中有关动画的文档。最简单的动画块就是这样(对不起,我现在附近没有mac,因此代码可能在复制和粘贴后无法正常工作)

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0f];
[myButton setFrame:newFrame];
[UIView commitAnimations];

答案 2 :(得分:1)

从上到下动画

CATransition *animation = [CATransition animation];
[animation setDuration:0.4];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromBottom];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[TopButton layer] addAnimation:animation forKey:@"SwitchToDown"];

答案 3 :(得分:0)

/ *常见的转换子类型。 * /

kCATransitionFromRight

kCATransitionFromLeft

kCATransitionFromTop

kCATransitionFromBottom

夫特:

    let transition1: CATransition = CATransition()
    let timeFunc1 : CAMediaTimingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    transition1.duration = 1.0
    transition1.timingFunction = timeFunc1
    transition1.type = kCATransitionPush
    transition1.subtype = kCATransitionFromRight
    self.yourBtnORViewRef.layer.addAnimation(transition1, forKey: kCATransition)

的Objective-C

CATransition *animation = [CATransition animation];
[animation setDuration:1.0];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[self.yourBtnORViewRef layer] addAnimation:animation forKey:@"SwitchToRight"];