简体   繁体   English

动画无法正常运行

[英]Animation doesn't work properly

my name is Lennart and I'm currently working on a Playground for the WWDC. 我叫Lennart,目前在WWDC的游乐场里工作。 But unfortunately I have a problem with animating a label. 但不幸的是,我对标签设置动画有问题。 Because of some reason the label doesn't even react to the animation, even though all the other labels do and it always animates one specific way (moves from the upper right corner to the middle). 由于某些原因,标签甚至对动画都没有反应,即使所有其他标签都可以,而且它总是以一种特定的方式设置动画(从右上角移动到中间)。 Here's my code: 这是我的代码:

startinglbl.text = "Tell us who you are"
    startinglbl.numberOfLines = 2
    startinglbl.lineBreakMode = .byWordWrapping
    startinglbl.frame = CGRect(x: 62, y: 62 + 10, width: 250, height: 100)
    startinglbl.font = UIFont(name: "HelveticaNeue-Bold", size: 40)
    startinglbl.textColor = UIColor.white
    startinglbl.textAlignment = .center
    startinglbl.alpha = 0

that's where I added some values to it and that's my animation: 那是我在上面添加一些值的地方,也是我的动画:

func startingAnimation() {
    UIView.animate(withDuration: 1, animations: {
        self.startinglbl.frame = CGRect(x: 62, y: 62, width: 250, height: 100)
        self.startinglbl.alpha = 1
    }) { (true) in
        UIView.animate(withDuration: 1, animations: { 
            self.fntextfield.frame = CGRect(x: 87, y: 250, width: 200, height: 30)
            self.fntextfield.alpha = 1
        }, completion: { (true) in
            UIView.animate(withDuration: 1, animations: { 
                self.lntextfield.frame = CGRect(x: 87, y: 300, width: 200, height: 30)
                self.lntextfield.alpha = 1
            }, completion: { (true) in
                UIView.animate(withDuration: 1, animations: { 
                    self.startingbtn.frame = CGRect(x: 137, y: 450, width: 100, height: 50)
                    self.startingbtn.alpha = 1
                })
            })
        })
    }
}

I would really appreciate your help guys Thank you very much 非常感谢您的帮助。非常感谢

keep in mind that if you are using autolayout. 请记住,如果您使用自动版式。 then frame based animation does not work. 那么基于帧的动画将不起作用。 like this : 像这样 :

CATransition* transition = [CATransition animation];
    transition.duration = 0.4;
    transition.type = kCATransitionMoveIn;
    transition.subtype = kCATransitionFromTop;
    [_eraserSliderContainer.layer addAnimation:transition
                              forKey:kCATransition];

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

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