0
UITextViewをビューに追加しようとしています。私はこのクラスを持っている:背景色が茶色に変わりますSwiftはUITextViewを編集できません。テキストを追加できません。
import UIKit
class TextAnnotation: UITextView {
var lastLocation:CGPoint?
var panRecognizer:UIPanGestureRecognizer?
override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
self.panRecognizer = UIPanGestureRecognizer(target:self, action: #selector(StampAnnotation.detectPan))
self.gestureRecognizers = [panRecognizer!]
self.text = "Text Field"
self.backgroundColor = UIColor.brownColor()
self.userInteractionEnabled = true
self.editable = true
self.frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: 200, height: 50)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func detectPan(recognizer:UIPanGestureRecognizer) {
let translation = recognizer.translationInView(self.superview!)
self.center = CGPointMake(lastLocation!.x + translation.x, lastLocation!.y + translation.y)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
// Promote the touched view
self.superview?.bringSubviewToFront(self)
// Remember original location
lastLocation = self.center
}
}
が、私はUITextViewの何をタップしたときにテキストが追加されないことは、私が編集可能に設定したときに、私が間違って何をやってどうなりますか?ここで
は、私はこのクラスを呼び出しています方法です:
let textCenter = touches.first!.locationInView(view)
let textView = TextAnnotation(frame: CGRect(x: textCenter.x, y: textCenter.y, width: 200, height: 50), textContainer: NSTextContainer())
view.addSubview(textView)
ジェスチャーを削除した場合、テキストを編集することはできますが、既定のテキストまたは作成中のテキストは表示されません。 – user979331
テキストが表示されないのはなぜですか? – user979331