Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IOS-按钮从右侧滑入动画_Ios_Animation - Fatal编程技术网

IOS-按钮从右侧滑入动画

IOS-按钮从右侧滑入动画,ios,animation,Ios,Animation,我不熟悉IOS编程。我的屏幕上有一个背景图像。我想要的是,当应用程序启动时,屏幕上会显示背景图像,然后在1秒后,屏幕右侧会出现两个按钮。我怎样才能做到这一点。这是我正在尝试做的图像 按钮1和按钮2必须首先不可见。1秒钟后,它们从右侧出现。 如果有任何与此类动画相关的教程,请共享您可以使用简单的UIView动画来实现这一点 将按钮x原点设置为大于屏幕大小的任何值,使其首先不可见。然后使用视图动画将按钮帧重置为可见值。例如,在视图中调用以下函数将出现:方法 - (void) animateButt

我不熟悉IOS编程。我的屏幕上有一个背景图像。我想要的是,当应用程序启动时,屏幕上会显示背景图像,然后在1秒后,屏幕右侧会出现两个按钮。我怎样才能做到这一点。这是我正在尝试做的图像

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

您可以使用简单的UIView动画来实现这一点

将按钮x原点设置为大于屏幕大小的任何值,使其首先不可见。然后使用视图动画将按钮帧重置为可见值。例如,在
视图中调用以下函数将出现:
方法

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

请参阅

设置按钮的x坐标,使按钮正好位于屏幕右侧的外侧

然后在
viewDidLoad()中尝试以下操作


您可以这样做,请注意,如果您想设置按钮显示方式的动画,必须使用
alpha=0.0f
(而不是
hidden=true
)隐藏它们。这样,您将有一个平滑的显示动画

这是:

首先,在您的
UIViewController
viewDidLoad
上,您必须设置一个1秒的
NSTimer
,然后让它调用将显示按钮的方法:

- (void) viewDidLoad {
    [super viewDidLoad];
    // Do your init stuff here

    // We will call your buttons as if they are declared as properties of your class, ask if you don't know how to set them
    self.button1.alpha = 0.0f;
    self.button2.alpha = 0.0f;

    // This will wait 1 sec until calling showButtons, where we will do the trick
     NSTimeInterval timeInterval = 1.0;
    [NSTimer scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector(showButtons) userInfo:nil repeats:NO];
 }

- (void) showButtons {
    [UIView beginAnimations:@"buttonShowUp" context:nil];
    [UIView setAnimationDuration:0.5]; // Set it as you want, it's the length of your animation

    self.button1.alpha = 1.0f;
    self.button2.alpha = 1.0f;

    // If you want to move them from right to left, here is how we gonna do it :
    float move = 100.0f; // Set it the way you want it
    self.button1.frame = CGRectMake(self.button1.frame.origin.x - move,
                                    self.button1.frame.origin.y,
                                    self.button1.frame.size.width,
                                    self.button1.frame.size.height);

    self.button2.frame = CGRectMake(self.button2.frame.origin.x - move,
                                    self.button2.frame.origin.y,
                                    self.button2.frame.size.width,
                                    self.button2.frame.size.height);

     // If you want to set them in the exact center of your view, you can replace 
     // self.button1.frame.origin.x - move
     // by the following
     // (self.view.center - self.button1.frame.size.width/2)
     // This way, your button will be centered horizontally

    [UIView commitAnimations];
}
如果您有任何问题,请询问

看这里。这应该对你有用。
- (void) viewDidLoad {
    [super viewDidLoad];
    // Do your init stuff here

    // We will call your buttons as if they are declared as properties of your class, ask if you don't know how to set them
    self.button1.alpha = 0.0f;
    self.button2.alpha = 0.0f;

    // This will wait 1 sec until calling showButtons, where we will do the trick
     NSTimeInterval timeInterval = 1.0;
    [NSTimer scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector(showButtons) userInfo:nil repeats:NO];
 }

- (void) showButtons {
    [UIView beginAnimations:@"buttonShowUp" context:nil];
    [UIView setAnimationDuration:0.5]; // Set it as you want, it's the length of your animation

    self.button1.alpha = 1.0f;
    self.button2.alpha = 1.0f;

    // If you want to move them from right to left, here is how we gonna do it :
    float move = 100.0f; // Set it the way you want it
    self.button1.frame = CGRectMake(self.button1.frame.origin.x - move,
                                    self.button1.frame.origin.y,
                                    self.button1.frame.size.width,
                                    self.button1.frame.size.height);

    self.button2.frame = CGRectMake(self.button2.frame.origin.x - move,
                                    self.button2.frame.origin.y,
                                    self.button2.frame.size.width,
                                    self.button2.frame.size.height);

     // If you want to set them in the exact center of your view, you can replace 
     // self.button1.frame.origin.x - move
     // by the following
     // (self.view.center - self.button1.frame.size.width/2)
     // This way, your button will be centered horizontally

    [UIView commitAnimations];
}