动画中的 UIView 幻灯片

Tre*_*ler 0 uiviewanimation ios swift

我在 UIView 中有一个文本字段,我想在用户访问该 VC 时将其滑入。这容易实现吗?如果是这样,我该怎么做?

Fre*_*ust 6

这是一个快速示例:

import UIKit

class ViewController: UIViewController {

    var textField: UITextField?

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func viewDidAppear(_ animated: Bool) {

        let textFieldFrame = CGRect(x: -200, y: 20, width: 200, height: 30)
        let textField = UITextField(frame: textFieldFrame)
        textField.placeholder = "Some Text"
        self.textField = textField

        self.view.addSubview(self.textField!)

        UIView.animate(
            withDuration: 0.4,
            delay: 0.0,
            options: .curveLinear,
            animations: {

                self.textField?.frame.origin.x = 100

        }) { (completed) in

        }
    }
}
Run Code Online (Sandbox Code Playgroud)