簡體   English   中英

輕掃手勢識別器

[英]Swipe gesture recognizer swift

我已經在互聯網上搜索了幾個小時,以了解如何使用“滑動手勢識別器”。 我不想編寫代碼,因為我已經嘗試了幾乎每個示例,但都行不通。 但是,我知道對象庫中有一個“滑動手勢識別器”,但是它似乎不起作用。 有人可以給我顯示指向我可以使用“對象庫”中的“滑動手勢識別器”的地方的鏈接,或者向我顯示如何做的地方嗎?

謝謝,

(如果我出於某種原因而寬泛,或者您不喜歡我的問題,請不要將此設為-1,請發表評論,然后我進行更改)。

崩潰日志:2016-01-09 10:59:33.392 Capitals [250:14059]-[Capitals.Alabama1 handleSwipes]:無法識別的選擇器已發送到實例0x14f695150 2016-01-09 10:59:33.397 Capitals [250:14059] *終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因是: ' - [Capitals.Alabama1 handleSwipes]:無法識別的選擇發送到實例0x14f695150' *第一擲調用堆棧:(0x184bdcf48 0x19984ff80 0x184be3c5c 0x184be0c00 0x184ae4cac 0x18a6eb330 0x18a314b5c 0x18a1a285c 0x18a6ec70c 0x18a1618b8 0x18a15e63c 0x18a1a06cc 0x18a19fcc8 0x18a1704a4 0x18a16e76c 0x184b94544 0x184b93fd8 0x184b91cd8 0x184ac0ca0 0x18fb40088 0x18a1d8ffc 0x10008a264 0x19a0928b8)libc ++ abi.dylib:以NSException類型的未捕獲異常終止

(Handle Swipes是函數的名稱)

這是代碼:

導入UIKit

類Alabama1:UIViewController {@IBOutlet弱var標簽:UILabel!

override func viewDidLoad() {
    super.viewDidLoad()

    let reveal = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes"))
    let next = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes"))

    // Do any additional setup after loading the view, typically from a nib.
    reveal.direction = .Up
    next.direction = .Left

    view.addGestureRecognizer(reveal)
    view.addGestureRecognizer(next)

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func handleSwipes(sender:UISwipeGestureRecognizer) {
    if (sender.direction == .Up) {
        label.text = "Motgomery"
    }

}





}

您在添加事件中缺少分號。 嘗試這樣:

let reveal = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
let next = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))

在swift3版本中:

   let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(MainMenuViewController.handleSwipes(_sender:)))

暫無
暫無

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

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