繁体   English   中英

加载UIView之后加载UIButton

[英]Load UIButton After UIView Loads

我在UIViewController的中心显示了一组按钮。 为了使按钮在视图加载时一个接一个地弹出/出现在视图上的效果,我试图找出在UIViewController加载后加载UIButton的方法,或者换句话说,在彼此之间加载一秒钟,以便它们快速加载,但视图加载后,该按钮会有一个可视化的动画弹出窗口。

有没有人有使用UIButton进行此操作的示例?

最初,当视图控制器收到对viewDidLoad的调用时,您需要设置按钮,使其具有零alpha

然后,在viewDidAppear:您可以配置一组动画以使用以下方式显示按钮:

[UIView animateWithDuration:<#(NSTimeInterval)#>
                      delay:<#(NSTimeInterval)#>
                    options:<#(UIViewAnimationOptions)#>
                 animations:<#^(void)animations#>
                 completion:<#^(BOOL finished)completion#>]

使用delay来分隔每个按钮的显示和animations块以指定按钮的显示方式。 在动画块中,可以将alpha设置为1以使按钮出现。 您还可以向按钮添加缩放transform ,使其大小发生变化(对于弹出效果)。

你可能想要这样的东西:

- (void)viewWillA pear:(BOOL)animated {
    [super viewWillAppear:animated];
    _button.alpha = 0;
    UIView animateWithDuration:1 animations:^{
        _button.alpha = 1;
    }];
}

您可以随时增加alpha。 从0.0f开始到1.0f结束。 它会使褪色效果,并开始隐形。

              yourButton.alpha = 0.0f;
             [yourView addSubview:yourButton];

             [UIView animateWithDuration:1.0
                  delay:0.0
                options: UIViewAnimationCurveEaseInOut
             animations:^{yourButton.alpha = 1.0;}
             completion:nil];

在viewDidApper方法中使用NSTimer跟随方法

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(targetMethod :) userInfo:nil repeats:NO];

// write targetMethod:每隔1秒调用一次此方法。 编写代码以在该方法中将按钮添加为屏幕的子视图,或者如果您可以控制按钮的可见性,则使按钮在targetMethod中可见。 当所有按钮完全加载后,使用NSTimer的invalidate方法停止调用targetMethod。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM