Reputation: 1712
I have a text field inside of a UIView that I want to slide in when the user gets to that VC. Is this easily achievable? If so, how can I do this?
Upvotes: 0
Views: 10955
Reputation: 6790
Here's a quick example:
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
}
}
}
Upvotes: 7