2015-06-04 203 views
0

我試圖讓用戶像在SnapChat應用程序一樣在屏幕周圍繪製UITextView。我嘗試了下面的代碼,但它似乎沒有工作。有什麼建議麼?我不會減少正在調用的detectPan方法。我必須重寫一些UITextFieldDelegate屬性嗎?在屏幕上拖動UITextView

var panRecognizer = UIPanGestureRecognizer(target:self, action:"detectPan:") 
text.addGestureRecognizer(panRecognizer) 

func detectPan(sender:UIPanGestureRecognizer) { 
     self.view.bringSubviewToFront(sender.view!) 
     var translation = sender.translationInView(self.view) 
     sender.view!.center = CGPointMake(sender.view!.center.x + translation.x, sender.view!.center.y + translation.y) 
     sender.setTranslation(CGPointZero, inView: self.view) 
} 
+0

如果在翻譯完成後添加'self.view.layoutIfNeeded()',它是否可以解決問題? – Dustin

回答

0

不知道這是否是最有效的方式去做這件事,但我把textview放在一個視圖和禁用用戶交互。然後做了一個輕擊手勢(使textview成爲第一響應者)和平移手勢(移動視圖)。