NiceGesture 1.0

NiceGesture 1.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Apr 2016
SPMSupports SPM

Maintained by lacklock.



  • By
  • lacklock

NiceGesture

Build Status

The best way to use UIGesture

Usage

TapGesture:

because tapGesture is only have one state,so it’s only have method whenTapped

  view.nc_addTapGestureWithConfigClosure { (tapGestureRecognizer) -> () in
            // Configure gesture recognizer,like this:
            tapGestureRecognizer.numberOfTapsRequired=2
        }.whenTapped {(tapGestureRecognizer) -> () in
            //doSomething()
        }

  // or you can directly do something 
  view.nc_whenTapped {(tapGestureRecognizer) -> () in
        //doSomething()
  }

LongPress,Pan,Pinch,Rotate,Swipe,ScreenEdgesPan:

if you want to cinfigure gesture,use this method:

  view.nc_addxxxxGestureWithConfigClosure({ (gestureRecognizer) -> () in
        //Configure gesture recognizer
  })

if you needn’t configure,use this method to start:

  view.nc_addxxxxGesture()

then,you can add hanlder function as you want:

   view.nc_addPanGesture()
       .whenBegan { (recognizer) -> Void in

       }.whenCancelled { (recognizer) -> Void in

       }.whenChanged { (recognizer) -> Void in

       }.whenEnded { (recognizer) -> Void in

       }.whenFailed { (recognizer) -> Void in

       }

a convenient way to use SwipeGesture:

   view.nc_whenSwipedInDirection(.Down) { (gestureRecognizer) in

        }

or if you want set one handler for many states,use whenStatesHappend:

lbState.nc_addPanGesture().whenStatesHappend([.Ended,.Changed]) { (gestureRecognizer) -> Void in

        }

Attention

Custom gestureRecognizerHandler is retained by UIGestureRecognizer , UIGestureRecognizer is retained by target view, so if you’re using self property remeber explicit [unowned self] to avoid retain cycle:

 lbState.nc_whenSwipedInDirection(.Down) {[unowned self]  (gestureRecognizer) in
            self.lbState.text="Down"
        }

Installation

Manual

Just copy the files which under NiceGesture folder to your project

Contact

Weibo : @没故事的卓同学

License

NiceGesture is available under the MIT license. See the LICENSE file for more info.