简体   繁体   中英

How do I make a label slide onto the screen when a button is pressed? SWIFT 2

I'm building an iOS app that takes some text from a website and displays it in a label when a button is pressed.

I'd like the label to move onto the screen from below when the button is pressed, how is this done in Swift 2?

I've started off using this code to move the label off the screen when the view appears, but I can't find a way to animate it back onto the screen

override func viewDidLayoutSubviews() {

label.center = CGPointMake(label.center.x, label.center.y - 400)

}

Very simple approach. Set the CGPoints to where you want to label positioned.

    UIView.animateWithDuration(1, animations: {
          label.center = CGPointMake(label.center.x, label.center.y+400)
    })

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