簡體   English   中英

使用touches將文本輸出到鍵盤

[英]Outputting text to keyboard with touchesBegan in Swift

我正在創建一個用於練習的自定義鍵盤,並且嘗試使用touchesBegan / Moved / Ended而不是典型的UIButton控件事件,因為這在我的項目中是必需的。 現在,我試圖在按鈕的一個框架包含觸摸點時簡單地輸出一些文本,如下所示:

override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {

    var touchPoint: UITouch = touches.anyObject() as UITouch


    if CGRectContainsPoint(button01.frame, touchPoint.locationInView(self.view))  {

          var output = textDocumentProxy as UITextDocumentProxy

          output.insertText(button01.outputText)


        }        
}

不能弄清楚為什么它不起作用,任何幫助將不勝感激。

當我將按鈕的userInteractionEnabled設置為false時,此問題已解決,因此觸摸實際上將由視圖注冊,而不是被頂部的UIButton占用。 希望這會幫助另一個人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM