Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.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_Swift - Fatal编程技术网

Ios 如果应用程序是第一次启动的,那么是一个简单的动画吗?

Ios 如果应用程序是第一次启动的,那么是一个简单的动画吗?,ios,swift,Ios,Swift,在swift中,我有一个应用程序,在第一次发布时会显示一个“教程”。我想要一个简单的动画,第一个动画在里面,第二个在后面。我希望它非常快。尽管如此,在我当前的代码中,当视图/应用程序加载时,一切都正常 代码: let welcomeLabel = UILabel() let learnToPlayButton = UIButton() welcomeLabel.alpha = 0 learnToPlayButton.alpha = 0 welcomeLabel.text = "Welcome t

在swift中,我有一个应用程序,在第一次发布时会显示一个“教程”。我想要一个简单的动画,第一个动画在里面,第二个在后面。我希望它非常快。尽管如此,在我当前的代码中,当视图/应用程序加载时,一切都正常

代码:

let welcomeLabel = UILabel()
let learnToPlayButton = UIButton()
welcomeLabel.alpha = 0
learnToPlayButton.alpha = 0
welcomeLabel.text = "Welcome to ReactFast!"
        welcomeLabel.font = UIFont(name: "HelveticaNeue-Light", size: 35)
        welcomeLabel.textAlignment = .Center
        welcomeLabel.textColor = UIColor.whiteColor()
        welcomeLabel.frame = CGRectMake(85, 30, 400, 200)
   learnToPlayButton.setTitle("Click here to learn how to play.", forState: .Normal)
        learnToPlayButton.setTitleColor(UIColor.whiteColor(), forState: .Normal)
        learnToPlayButton.titleLabel.font = UIFont(name: "HelveticaNeue-UltraLight", size: 35)
        learnToPlayButton.titleLabel.textAlignment = .Center
        learnToPlayButton.addTarget(self, action: "learnToPlay:", forControlEvents: .TouchUpInside)
        learnToPlayButton.frame = CGRectMake(37, 70, 500, 200)
if NSUserDefaults.standardUserDefaults().boolForKey("hasLaunchedOnce") {
            //app has already launched before
        } else {
            NSUserDefaults.standardUserDefaults().setBool(true, forKey: "hasLaunchedOnce")
            NSUserDefaults.standardUserDefaults().synchronize()
            //first time launch

            UIView.animateWithDuration(1.5, animations: {
                self.view.addSubview(self.welcomeLabel)
                self.view.addSubview(self.learnToPlayButton)
                self.welcomeLabel.alpha = 1.0
                self.learnToPlayButton.alpha = 1.0
                })
        }

缺少动画很可能是由动画代码的放置引起的。viewDidLoad在视图控制器的生命周期中太早,您无法尝试在那里设置任何动画

您应该做的是将所有设置代码保留在viewDidLoad中,然后在ViewDidDisplay:方法中添加动画代码,以便在视图实际出现在屏幕上时立即开始动画