2017-09-25 37 views
0

我需要檢測所有的左滑動和右滑動包括向上滑動。我的意思是我需要檢測180度區域內的所有揮杆動作,我不確定是否足夠清晰。當我添加.up .right和.left時,它沒有檢測到左對角線等對角線,我應該怎麼做?謝謝!Swift UISwipeGestureRecognizer如何檢測對角線滑動?

+0

。 –

+0

@BaranKaraoğuz「泛」是什麼意思?實際上這對我來說是一個新名詞。 –

+0

Dostumtürksünzatenkasmanınanlamıyok:D PanGesture bir view yada nesneye dokunup onu hareket etmeye yaniparmağınıntelefondakikordinatlarınıanlayan model Buyüzdensöylediğinşeyipangesture yapabilirsin swipe'dan ziyade。 –

回答

1

UIPanGestureRecognizer是去這樣的方式:你應該嘗試PanGestureRecognizer

private var panRec: UIPanGestureRecognizer! 
private var lastSwipeBeginningPoint: CGPoint? 

override func viewDidLoad() { 
    panRec = UIPanGestureRecognizer(target: self, action: #selector(ViewController.handlePan(recognizer:))) 
    self.view.addGestureRecognizer(panRec) 
} 

func handlePan(recognizer: UISwipeGestureRecognizer) { 
    if recognizer.state == .began { 
     lastSwipeBeginningPoint = recognizer.location(in: recognizer.view) 
    } else if recognizer.state == .ended { 
     guard let beginPoint = lastSwipeBeginningPoint else { 
      return 
     } 
     let endPoint = recognizer.location(in: recognizer.view) 
     // TODO: use the x and y coordinates of endPoint and beginPoint to determine which direction the swipe occurred. 
    } 
} 
相關問題