动画中的 UIView 幻灯片

Posted

技术标签:

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

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

【问题讨论】:

查看本教程appcoda.com/custom-view-controller-transitions-tutorial 抱歉 - 问题的细节有点不清楚。 【参考方案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

        
    

【讨论】:

以上是关于动画中的 UIView 幻灯片的主要内容,如果未能解决你的问题,请参考以下文章