【发布时间】:2017-01-24 14:43:29
【问题描述】:
将 CATextLayer 添加到 UIImageView 图层后如何通过拖动来移动图层。因为我将向 UIImageView 添加多个图层。那么,我如何知道我点击了哪个图层并将其移动到另一个位置?
这是我绘制文本的代码:
func addText() -> CATextLayer{
let rect:CGRect = CGRect(x: 50, y: 600, width: 120, height: 60)
let myAttributes = [
NSFontAttributeName: UIFont(name: "HelveticaNeue-Thin", size:18)!,
NSForegroundColorAttributeName: UIColor.black.cgColor
] as [String : Any]
let myAttributedString = NSAttributedString(string: "TEST STRING", attributes: myAttributes)
let textLayer = CATextLayer()
textLayer.frame = rect
textLayer.string = myAttributedString
textLayer.position = CGPoint(x:150,y:400)
textLayer.alignmentMode = kCAAlignmentCenter
return textLayer
}
【问题讨论】:
-
我已经解决了使用自定义视图的问题并定义了事件处理程序来控制拖动。
标签: ios swift uiimageview uigesturerecognizer calayer