title: Using UIGestureRecognizer in Swift
body: <p>I'm trying to subclass <code>UIButton</code> with <code>UIGestureRecognizer</code> to add different targets to the button, depending on the initial axis along which the drag is moving. I've gotten as far as this:</p>
  
  <pre><code>class restrictedDragButton: UIButton {
      override func gestureRecognizerShouldBegin(gestureRecognizer: UIPanGestureRecognizer) -&gt; Bool {
          let translation = gestureRecognizer.translationInView(self)
          if abs(translation.y) &gt; abs(translation.x) {
              return true
          } else {
              return false
          }
      }
  }
  </code></pre>
  
  <p>This gives me the error <code>Overriding method with selector 'gestureRecognizerShouldBegin:' has incompatible type '(UIPanGestureRecognizer) -&gt; Bool'</code>. I've added the delegate to my view controller, so I'm not sure what else to do.</p>
  
  <p>Ultimately, I'd like to be able to say something like:</p>
  
  <pre><code>if myButton.gestureRecognizerShouldBegin() {  // returns vertical
      myButton.addTarget(...)  // vertical drag selector
  } else {
      myButton.addTarget(...)  // horizontal drag selector
  }
  </code></pre>
  
  <p>Any help would be appreciated. Thanks!</p>