【问题标题】:iOS Make Buttons and Labels appear after some TimeiOS 使按钮和标签在一段时间后出现
【发布时间】:2014-04-28 10:06:40
【问题描述】:

目前我正在创建一个应用程序,当您第一次启动它时,有一些介绍文本和 2 个按钮。 1个按钮跳过教程,另一个按钮做教程。我希望这 2 个按钮和那些标签在一定时间后出现并带有淡入动画。谁能给我一些代码示例?我已经尝试过搜索,但结果对我没有帮助。

我更新了一些代码。现在看起来像这样:

.h 文件:

   @interface startViewController : UIViewController {

IBOutlet UIButton *notourb;
IBOutlet UIButton *tourb;
IBOutlet UILabel *welcomeLabel;

}


- (void)shownotourb;
- (void)showtourb;
- (void)showwLabel;

还有 .m 文件(我将只显示按钮中的代码,因为我想出了如何以另一种方式制作标签):

- (void)viewDidLoad
{
    [super viewDidLoad];

       [self performSelector:@selector(shownotourb) withObject:nil afterDelay:2.0];
       [self performSelector:@selector(showtourb) withObject:nil afterDelay:2.5];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)shownotourb {

    [UIView animateWithDuration:10.0
                          delay:1.0

                        options:UIViewAnimationCurveEaseInOut
                     animations:^ {
                         [self.view addSubview:notourb];

                     }
                     completion:^(BOOL finished){}];
 }

- (void)showtourb {

    [UIView animateWithDuration:10.0
                          delay:1.0

                        options:UIViewAnimationCurveEaseInOut
                     animations:^ {
                         [self.view addSubview:tourb];

                     }
                     completion:^(BOOL finished){}];


}

【问题讨论】:

  • 检查CABasicAnimation 概念,这将帮助您了解淡入淡出动画。并延迟performSelector:withObject:afterDelay: ..
  • @Niclas 检查我的答案。

标签: ios animation uibutton


【解决方案1】:

创建一个将按钮添加到视图中的方法,并使用performSelector:afterDelay 方法像这样添加它们:

在你的viewDidLoad:

    [self performSelector:@selector(addButtonsToView) withObject:nil afterDelay:5.0];

并添加此方法以添加您的按钮:

-(void)addButtonsToView
{
[UIView animateWithDuration:10.0
                  delay:1.0

                    options:UIViewAnimationCurveEaseInOut
                 animations:^ {
                     [self.view addSubview:button1];
                     [self.view addSubview:button2];

                 }
                 completion:^(BOOL finished){}];
}

希望对你有帮助:)

【讨论】:

  • 您能看看我的编辑并帮助我吗?
猜你喜欢
  • 2017-08-31
  • 1970-01-01
  • 2013-06-02
  • 2015-09-14
  • 1970-01-01
  • 1970-01-01
  • 2017-11-21
  • 2020-11-08
  • 1970-01-01
相关资源
最近更新 更多