OGeek|极客世界-中国程序员成长平台

标题: ios - 用手势快速移动标签位置 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:15
标题: ios - 用手势快速移动标签位置

我的 View Controller 中有一个标签。每次点击标签时,我都试图将标签的位置向左移动 50 点。这是我到目前为止所拥有的,但我的标签不会在模拟中移动。我确实对标签有限制。它大约有 100 宽和 50 高,并且也在 View Controller 中居中。

    override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    let tapGesture = UITapGestureRecognizer(target: gestureLabel, action: #selector(moveLabel))
    gestureLabel.addGestureRecognizer(tapGesture)

}

func moveLabel(){
    if(left){
        moveLeft()
    }
    else{
        moveRight()
    }

}

func moveLeft(){
    let originalX = gestureLabel.frame.origin.x
    if(originalX < 0){
        bringIntoFrame()
    }
    else{
        gestureLabel.frame.offsetBy(dx: -50, dy: 0)
    }
}



Best Answer-推荐答案


UILabel 的 userInteractionEnabled 默认为 false。尝试将其设置为 true

关于ios - 用手势快速移动标签位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42823051/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4