[英]Number of fingers touching screen (Swift 2.0)
我有個問題 !
我希望我的iPhone顯示多少手指觸摸屏幕...我使用了touchesBegan和touchesEnded。 當我同時用手指(2、3或4 ...)觸摸時,我的iPhone僅顯示有多少手指觸摸屏幕。 我希望它在添加一個或多個手指時顯示手指數...
非常感謝您的幫助...
PS:對不起,我的英語
Swift 3的更新:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
var countTouch = event?.allTouches?.count
//Do whatever you want with that
}
如果您想知道它是否隨時更改,請在touchesMoved中進行相同的操作並將其放入數組中,您將能夠對其進行分析或直接將其打印出來。
像這樣 :
var countTouch:[Int] = []
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
countTouch.append((event?.allTouches?.count)!) //Not really necessary
//Do whatever you want with that
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
countTouch.append((event?.allTouches?.count)!)
}
希望它對某人有所幫助,請不要猶豫進行編輯或改進。 我是Swift的初學者,所以完全有可能出錯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.