gpt4 book ai didi

ios - 持续更新 UILabel 框架和文本

转载 作者:搜寻专家 更新时间:2023-11-01 07:22:07 24 4
gpt4 key购买 nike

我正在尝试使用 touchMoved 使 uilabel 跟随我的手指移动。我正在将当前帧更新为标签文本。

标签被关闭但没有相应移动。如果我评论任何人喜欢只移动或只更新文本它的工作

最佳答案

我为您制作了一个示例,其中您有一个 UILabel,然后您将平移手势识别器添加到其中,然后根据 super View View 中的位置更改框架,例如它在这里: self.view。请记住为您的 UILabel 添加 userInteractionEnabled = true。祝你好运

@IBOutlet var label: UILabel!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(self.handlePan(_:)))
label.addGestureRecognizer(panGestureRecognizer)
label.userInteractionEnabled = true

}

func handlePan(gestureRecognizer: UIPanGestureRecognizer) {

let location = gestureRecognizer.locationInView(self.view)

var frame = label.frame
frame.origin.x = location.x
frame.origin.y = location.y
label.frame = frame
}

关于ios - 持续更新 UILabel 框架和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38306974/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com