发布于 2016-02-15 11:28:51 | 194 次阅读 | 评论: 0 | 来源: 网友投递
Swift编程语言
SWIFT,苹果于2014年WWDC(苹果开发者大会)发布的新开发语言,可与Objective-C*共同运行于Mac OS和iOS平台,用于搭建基于苹果平台的应用程序。
1.UITapGestureRecognizer 点击/双击手势
var tapGesture = UITapGestureRecognizer(target: self, action: "handleTapGesture:")
//设置手势点击数,双击:点2下
tapGesture.numberOfTapsRequired = 2
self.view.addGestureRecognizer(tapGesture)
var pinchGesture = UIPinchGestureRecognizer(target: self, action: "handlePinchGesture:")
self.view.addGestureRecognizer(pinchGesture)
var rotateGesture = UIRotationGestureRecognizer(target: self, action: "handleRotateGesture:")
self.view.addGestureRecognizer(rotateGesture)
var panGesture = UIPanGestureRecognizer(target: self, action: "handlePanGesture:")
self.view.addGestureRecognizer(panGesture)
var swipeGesture = UISwipeGestureRecognizer(target: self, action: "handleSwipeGesture:")
swipeGesture.direction = UISwipeGestureRecognizerDirection.Left //不设置是右
self.view.addGestureRecognizer(swipeGesture)
var longpressGesutre = UILongPressGestureRecognizer(target: self, action: "handleLongpressGesture:")
//长按时间
// longpressGesutre.minimumPressDuration
//所需触摸次数
/// longpressGesutre.numberOfTouchesRequired
self.view.addGestureRecognizer(longpressGesutre)
UIGestureRecognizerState 枚举定义如下
enum UIGestureRecognizerState : Int {
case Possible // the recognizer has not yet recognized its gesture, but may be evaluating touch events. this is the default state
case Began // the recognizer has received touches recognized as the gesture. the action method will be called at the next turn of the run loop
case Changed // the recognizer has received touches recognized as a change to the gesture. the action method will be called at the next turn of the run loop
case Ended // the recognizer has received touches recognized as the end of the gesture. the action method will be called at the next turn of the run loop and the recognizer will be reset to UIGestureRecognizerStatePossible
case Cancelled // the recognizer has received touches resulting in the cancellation of the gesture. the action method will be called at the next turn of the run loop. the recognizer will be reset to UIGestureRecognizerStatePossible
case Failed // the recognizer has received a touch sequence that can not be recognized as the gesture. the action method will not be called and the recognizer will be reset to UIGestureRecognizerStatePossible
}