UIView快速更改其位置 [英] UIView changing its position in swift

查看:167
本文介绍了UIView快速更改其位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过触摸按钮使UIView从其原始位置向上滑动,然后通过触摸按钮将UIView滑回原位?使用Swift和Xcode 6.

How do I make a UIView slide up with a touch of a button from its original position and them bring it back down with a touch of a button? Using Swift and Xcode 6.

我目前已经尝试过:

@IBOutlet weak var DynView: UIView!

@IBAction func btnUp(sender: AnyObject) {

}

推荐答案

您必须实现一个动画,更改单击时DynView位置.这是一个示例:

You have to implement an animation changing the DynView position on click. Here's an example:

@IBAction func btnUp(sender: AnyObject) {
    let xPosition = DynView.frame.origin.x
    let yPosition = DynView.frame.origin.y - 20 // Slide Up - 20px

    let width = DynView.frame.size.width
    let height = DynView.frame.size.height

    UIView.animateWithDuration(1.0, animations: {
        dynView.frame = CGRect(x: xPosition, y: yPosition, width: width, height: height)
    })
}

这篇关于UIView快速更改其位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆