简体   繁体   中英

Animation doesn't work properly

my name is Lennart and I'm currently working on a Playground for the 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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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