IOS - 按钮从右侧动画中滑入

时间:2014-04-03 09:22:49

标签: ios animation

我是IOS编程新手。我的屏幕上有背景图片。我想要的是当应用程序启动带有背景图像的屏幕显示,然后在1秒后2个按钮从屏幕右侧出现。我怎样才能做到这一点。这是我想要做的图像

enter image description here

按钮1和按钮2必须首先不可见。 1秒钟后,他们从右侧出现。 如果有任何与此类动画相关的教程,请分享

3 个答案:

答案 0 :(得分:1)

您可以使用简单的UIView动画来实现此目的。

将按钮x原点设置为大于屏幕尺寸的任何值,以便首先看不到它。然后使用视图动画将按钮框重置为可见值。例如,在viewWillAppear:方法中调用以下函数。

- (void) animateButton {

  // Setting button origin to value greater than the view width.
  CGRect frame = button.frame;
  frame.origin.x = self.view.frame.size.width+10;// or set any value > 320
  button.frame = frame;

    [UIView animateWithDuration:0.5
                          delay:2.0
                        options: UIViewAnimationCurveEaseOut
                     animations:^{
                         button.frame = CGRectMake(20, 100, 60, 25) ;// Any value according to your requirement
                     } 
                     completion:^(BOOL finished){
                         NSLog(@"Done!");
                     }];
}

参考Tutorial

答案 1 :(得分:0)

设置按钮' x坐标使得按钮位于右侧屏幕之外。

然后在viewDidLoad()

中尝试以下操作
[UIView animateWithDuration:0.5
                              delay:1.0
                            options:NO
                         animations:^{ change your button x co- ordinate here to the co-ordinate you need it on finally}
                         completion:NULL];

答案 2 :(得分:0)

您可以这样做,请注意,如果您想要设置按钮显示方式的动画,则必须使用alpha = 0.0f(而不是hidden = true)隐藏它们。这样,你就可以顺利地显示动画了!

这是:

首先,在您viewDidLoad的{​​{1}}上,您必须设置{1}} 1秒,然后让它调用让按钮出现的方法:

UIViewController

询问您是否有任何问题!