問題描述
Swift 2 中的遊戲 ‑ “touchesBegan”? (Game in Swift 2 ‑ "touchesBegan"?)
我想構建一個遊戲,當我觸摸和拖動時,它會在觸摸的位置創建一條與拖動方向相同的線,並在遊戲的邊界處結束(在本例中是我的框架)。
關於如何解決這個問題的任何提示?
參考解法
方法 1:
Your search term in UIPanGestureRecognizer.
You'd create a pan gesture recognizer and attach it to your view. In the method that it calls, look for the state UIGestureRecognizerStateBegan. Record the start position, then respond to calls to your action method with the state UIGestureRecognizerStateChanged.
That should be enough to get you started. As Matt says, this is a fairly common use case, so you should be able to find sample code online if you can't work this out from the docs.