关于ios的一些手势(UIGestureRecognizer)
2012-11-09 10:51:33| 分类: object-c ios|字号 订阅
一:手势事件类型
1.父类
UIGestureRecognizer 是一个抽象类,是所有手势事件的父类。
The concrete subclasses of UIGestureRecognizer are the following:
UITapGestureRecognizer
UIPinchGestureRecognizer
UIRotationGestureRecogni
UISwipeGestureRecognizer
UIPanGestureRecognizer//拖拽
UILongPressGestureRecogn
2,如何添加手势事件及响应
(1)添加:调用 UIVIEW及其子类的
(2)响应函数样式比如是下面两种的一种形式
- -
(void)viewDidLoad { - //---tap
gesture--- - UITapGestureRecognizer
*tapGesture =[[UITapGestureRecognizer alloc] - initWithTarget:self
- action:@selector(handleTapGesture:)];
- tapGesture.numberOfTapsRequired
= 2; - [imageView
addGestureRecognizer:tapGesture]; - [tapGesture
release]; - [super
viewDidLoad]; - }
- //---handle
tap gesture--- - -(IBAction)
handleTapGesture:(UIGestureRecognizer *) sender { - if
(sender.view.contentMode == UIViewContentModeScaleAs pectFit) - sender.view.contentMode
= UIViewContentModeCenter; - else
- sender.view.contentMode
= UIViewContentModeScaleAs pectFit; - }
3。
UITapGestureRecognizer
UIPinchGestureRecognizer
@property(nonatomic) CGFloat scale,放大缩小因子
@property(nonatomic, readonly) CGFloat velocity
UIRotationGestureRecogni
UISwipeGestureRecognizer
typedef enum {
} UISwipeGestureRecognizer
UIPanGestureRecognizer
– translationInView:
A point identifying the new location of a view in the coordinate system of its designated superview.
(一个点确定一个新的位置在其指定的父视图的坐标系统)
– setTranslation:inView:
The velocity of the pan gesture, which is expressed in points per second. The velocity is broken into horizontal and vertical components.
(手势的速度,这是表示在每分每秒。速度分解为水平和垂直分量。)
– velocityInView:
- (CGPoint)velocityInView:(UIView *)view
UILongPressGestureRecogn
手指事件生命周期(状态)
取得当前手势状态
@property(nonatomic,readwrite) UIGestureRecognizerState
Possible ----> Began ----> [Changed] ----> Cancelled
Possible ----> Began ----> [Changed] ----> Ended
typedef enum {
UIGestureRecognizerState