可拖动的UITextView无响应

时间:2015-08-15 14:28:24

标签: ios swift uitextview draggable

我创建了一个需要拖动的自定义UITextView,这是我使用的代码:

class DraggableView: UITextView {

var lastLocation:CGPoint = CGPointMake(0, 0)

override init(frame: CGRect, textContainer: NSTextContainer?) {
    super.init(frame: frame, textContainer: textContainer)
    // Initialization code
    var panRecognizer = UIPanGestureRecognizer(target:self, action:"detectPan:")
    self.gestureRecognizers = [panRecognizer]

    self.editable = true
    self.selectable = true
    self.backgroundColor = UIColor.redColor()
}

required init(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

func detectPan(recognizer:UIPanGestureRecognizer) {
    var translation  = recognizer.translationInView(self.superview!)
    self.center = CGPointMake(lastLocation.x + translation.x, lastLocation.y + translation.y)
}

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
    // Promote the touched view
    //self.superview?.bringSubviewToFront(self)

    // Remember original location
    lastLocation = self.center
}
}

出现但问题是我无法写任何内容或与之互动,我只能移动它。

有什么问题?

1 个答案:

答案 0 :(得分:0)

我认为你应该替换代码

<li class="corner-all" data-value="1aj"></li>
<li class="corner-all" data-value="2aj"></li>
<li class="corner-all" data-value="3aj"></li>

$('li[data-value="1aj"]').click(function(){
    alert('This item is clciked');
});

self.gestureRecognizers = [panRecognizer]

我认为必须有一个属于gestureRecognizers的手势才能告诉textView成为第一响应者。