iPhone 触摸时UITouch的常用方法及属性
再UIView中,可以重些以下四个方法来来控制用户的触摸动作:
?
?
- - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;- (void)touchesMoved:(NSSet?*)touches withEvent:(UIEvent?*)event;- (void)touchesEnded:(NSSet?*)touches withEvent:(UIEvent?*)event;- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
通过NSSet count 可以获知触摸的指头的个数. Set中每一个元素就是UITouch对象.从UITouch对象中可以获取很多有用的信息.
[touch phase] 就可以获知触摸的方式,它是一个枚举类型来的.
?
typedef enum {
? ? UITouchPhaseBegan, ? ? ? ? ? ? // whenever a finger touches the surface.
? ? UITouchPhaseMoved, ? ? ? ? ? ? // whenever a finger moves on the surface.
? ? UITouchPhaseStationary,? ? ? ? // whenever a finger is touching the surface but hasn't moved since the previous event.
? ? UITouchPhaseEnded, ? ? ? ? ? ? // whenever a finger leaves the surface.
? ? UITouchPhaseCancelled, ? ? ? ? // whenever a touch doesn't end but we need to stop tracking (e.g. putting device to face)
} UITouchPhase;
?
?
touch?tapCount 可以获取这个触摸的点击次数.(类似双击鼠标,如果双击就是2次)
touch timestamp 获取触摸的时间戳,这样可以计算一些点击的频率等应用.
touch locationInView: 获取坐标系,在某个view中
touch?previousLocationInView: 获取在某个view中的前一次坐标系
touch?gestureRecognizers 这个3.2新增加的(iPad),用于判断手势用
?
新增加的手势判断有以下这几种:
?
?
UILongPressGestureRecognizerUIPanGestureRecognizerUIPinchGestureRecognizerUIRotationGestureRecognizerUISwipeGestureRecognizerUITapGestureRecognizer如果想兼容早期的版本,并且不是在iPad中,那么手势暂时还是只能手动实现.不知道OS4是否已经在iPhone的SDK中增加了这个手势识别.