2016-07-17 14 views
1

浮動小数点値を関数handleTapに渡すにはどうすればよいですか?私は正しいパラメータの署名を設定しているが、中にfloat値を渡す方法がないように思える。UITapGestureRecognizerに追加パラメータを渡すには?

let tapped = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:digit:))) 
tapped.numberOfTapsRequired = 1 
mycontrol.addGestureRecognizer(handleTap) 


func handleTap(recognizer: UITapGestureRecognizer, aFloat: Float) { 
    //do something here 
} 
+1

あなたができません。フロートはどこから来たと思われますか? – dan

+0

もちろん、私はそれを供給します。 – 4thSpace

+0

おそらく、ジェスチャー認識機能の使い方や別のパラメータを渡す必要があるような、もう少しコンテキストを提供することができます – Gerald

答えて

2

あなたはUITapGestureRecognizerのサブクラスであるあなた自身のTapGestureRecongnizerクラスを作成することによって、これを達成することができます。例を以下に示す: -

class MyTapGesture: UITapGestureRecognizer { 
var floatValue = 0.0 

}

クラスのViewController:のUIViewController {

override func viewDidLoad() { 
    super.viewDidLoad() 
    let tapped = MyTapGesture.init(target: self, action: #selector(handleTap)) 
    tapped.floatValue = 5.0 
    tapped.numberOfTapsRequired = 1 
    view.addGestureRecognizer(tapped) 
} 

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

func handleTap(recognizer: MyTapGesture) { 
    print(recognizer.floatValue) 
} 

}

関連する問題