【问题标题】:UIView slide in animation动画中的 UIView 幻灯片
【发布时间】:2016-03-31 18:06:45
【问题描述】:

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

【问题讨论】:

标签: ios swift uiviewanimation


【解决方案1】:

这是一个简单的例子:

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

        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-12
    • 2015-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-10
    相关资源
    最近更新 更多