【发布时间】:2016-03-31 18:06:45
【问题描述】:
我在 UIView 中有一个文本字段,当用户访问该 VC 时,我想将其滑入。这很容易实现吗?如果是这样,我该怎么做?
【问题讨论】:
-
抱歉 - 问题的细节有点不清楚。
标签: ios swift uiviewanimation
我在 UIView 中有一个文本字段,当用户访问该 VC 时,我想将其滑入。这很容易实现吗?如果是这样,我该怎么做?
【问题讨论】:
标签: ios swift uiviewanimation
这是一个简单的例子:
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
}
}
}
【讨论】: