Swift 未在正确的时间或位置淡入的对象

Swift 未在正确的时间或位置淡入的对象,swift,Swift,我很难让一些物体淡入。有两件事出了问题:a。看起来标签从屏幕的左上角开始,然后被移动到正确的位置,b。它们并没有真正消失。如果有人能看看我的代码,给我一些想法,我会非常感激。谢谢 @objc func fadeOut1(view: UIView, delay: TimeInterval) { UIView.animate( withDuration: 0.1, delay: delay, animations

我很难让一些物体淡入。有两件事出了问题:a。看起来标签从屏幕的左上角开始,然后被移动到正确的位置,b。它们并没有真正消失。如果有人能看看我的代码,给我一些想法,我会非常感激。谢谢

@objc func fadeOut1(view: UIView, delay: TimeInterval) {
        UIView.animate(
            withDuration: 0.1,
            delay: delay,
            animations: { () -> Void in
                self.option1.alpha = 0
                self.option2.alpha = 0
                self.option3.alpha = 0
                self.option4.alpha = 0
                self.continueButton.alpha = 0
                self.question.alpha = 0
                self.slide2()

        })
    }

@objc func fadeIn(view: UIView, delay: TimeInterval) {
        UIView.animate(
            withDuration: 1,
            delay: delay,
            animations: { () -> Void in self.view.alpha = 1
        })
    }

    let background = UIImage(named: "nyc")
    var imageView : UIImageView!
    let answer = UILabel(frame: CGRect(x: 0, y: 0, width: 350, height: 300))
    let continueLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 50))


    func slide2() {

        imageView = UIImageView(frame: view.bounds)
        imageView.contentMode =  UIView.ContentMode.scaleAspectFill
        imageView.clipsToBounds = true
        imageView.image = background
        imageView.center = view.center
        view.addSubview(imageView)
        self.view.sendSubviewToBack(imageView)
        fadeIn(view: imageView, delay: 0)

        answer.text = "Believe it or not, you can actually invest in all of these things! In our case though, we'll be focusing on the stock market."
        answer.textAlignment = .center
        answer.numberOfLines = 7
        answer.textColor = UIColor.black
        answer.center = CGPoint(x: self.view.center.x, y: self.view.center.y/2-20)
        answer.font = UIFont.boldSystemFont(ofSize: 30)
        view.addSubview(answer)
        fadeIn(view: answer, delay: 2)

        continueLabel.center = CGPoint(x: self.view.center.x, y: self.view.center.y*1.7+20)
        continueLabel.text = "Swipe left to continue"
        continueLabel.textAlignment = .center
        continueLabel.font = UIFont.boldSystemFont(ofSize: 25)
        continueLabel.textColor = UIColor.white
        view.addSubview(continueLabel)
        fadeIn(view: continueLabel, delay: 2)

        let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(toNext(sender:)))
        leftSwipe.direction = .left
        view.addGestureRecognizer(leftSwipe)
    }

你在哪里调用代码中的
slide2()
。例如,
viewDidLoad
将是一个非常错误的位置。另外,你知道,你所有的位置都计算错误;决不能根据子视图的帧或中心设置子视图的帧或中心,因为它们是不兼容的坐标系。@valosip slide2()是在淡出函数中调用的。我将代码编辑成原始问题。