UITouch

Overview

概述

A UITouch object represents the presence or movement of a finger on the screen for a particular event. You access UITouch objects through UIEvent objects passed into responder objects for event handling.

UITouch对象描绘了手指在屏幕上的移动和交互行为的详细事件。你使用使用UITouch对象把UIEvent对象传递刀响应对象中来为事件控制服务。

A UITouch object includes methods for accessing the view or window in which the touch occurred and for obtaining the location of the touch in a specific view or window. it also lets you find out when the touch occurred, whether the user tapped more than once, whether the finger is swiped (and if so, in which direction), and the phase of a touch—that is, whether it began, moved, or ended the gesture, or whether it was canceled.

一个UITouch对象包含了方法用来获取视图或者窗口中发生的触摸事件的位置然後传递到视图或者窗口中去。他也让你什么时候发生了触摸事件,用户触摸了一次还是多次,手指是否是滑过(如果是,会判断那个方向),和触摸的开始,移动,或者结束手势动作或者取消动作。

A UITouch object is persistent throughout a multi-touch sequence. You should never retain an UITouch object when handling an event. If you need to keep information about a touch from one phase to another, you should copy that information from the UITouch object.

一个UITouch对象贯穿了多点触摸的次序。你不应该在控制一个事件的时候保持UITouch对象。如果你需要保存一个触摸信息然後传递到另一个其他地方,那你需要复制UITouch对象的信息。

See Event Handling in iPhone Application Programming Guide for further information on event handling.

你可以在 iPhone Application Programming Guide 查看 事件控制这一章来获取更多有关事件控制的信息。


Tasks

任务

Getting the Location of Touches

获取触摸的位置信息

– locationInView:
– previousLocationInView:
     view  property
     window  property

Getting Touch Attributes

获取触摸的属性

tapCount  property
timestamp  property
phase  property

Properties

属性

For more about Objective-C properties, see “Properties” in The Objective-C 2.0 Programming Language.

有关更多Objective-C属性的信息,查看 The Objective-C 2.0 Programming Language 中的属性一章


phase

The type of touch. (read-only)

触摸的类型(只读)

@property(nonatomic, readonly) UITouchPhase phase

Discussion

讨论

The property value is a constant that indicates whether the touch began, moved, ended, or was canceled. For descriptions of possible UITouchPhase values, see “Touch Phase.”

这个属性是一个静态的值当触摸事件开始,移动,结束,或者取消时就定义了。有关 UITouchPhase 值的各种可能性描述你可以查看 Touch Phase 。

Availability

可用平台

Available in iPhone OS 2.0 and later.

可用于iPhone OS 2.0或者更新

Related Sample Code

关联的例子代码

MoviePlayer

Declared In

定义文件

UITouch.h


tapCount

The number of times the finger was tapped for this given touch. (read-only)

一个数字标识手指在屏幕上触碰次数(只读)

@property(nonatomic, readonly) NSUInteger tapCount

Discussion

讨论

The value of this property is an integer indicating the number of times the user tapped their fingers on a certain point within a predefined period. If want to determine whether the user single-tapped, double-tapped, or even triple-tapped a particular view or window, you should evaluate the value returned by this method.

这个值是一个整数用来标识用户使用他们的手指在屏幕上某段时间内某个手指点击的次数。如果想要知道用户是单击,双击或者三击视图或者窗口的话,你需要判定这个值。

Availability

可用平台

Available in iPhone OS 2.0 and later.

可用于iPhone OS 2.0或者更新

Related Sample Code

关联的例子代码

HeadsUpUI Touches

Declared In

定义文件

UITouch.h


timestamp

The time when the touch occurred or when it was last mutated. (read-only)

触摸发生的事件或者最後发生的时刻。(只读)

@property(nonatomic, readonly) NSTimeInterval timestamp

Discussion

讨论

The value of this property is the time, in seconds, since system startup the touch either originated or was last changed. You can store and compare the initial value of this attribute to subsequent timestamp values of the UITouch instance to determine the duration of the touch and, if it is being swiped, the speed of movement.

这是值的属性是时间,在很短的时间内,当系统启动触摸感应无论在开始或者最後的响应。你可以存储和对比UITouch实例的timestamp的初始的值来计算持续的时间以此来判断他是否是滑动或者滑动的速度。

Availability

可用平台

Available in iPhone OS 2.0 and later.

可用于iPhone OS 2.0或者更新

Declared In

定义文件

UITouch.h


view

The view in which the touch initially occurred. (read-only)

触摸事件发生的视图。(只读)

@property(nonatomic, readonly, retain) UIView *view

Discussion

讨论

The value of the property is the view object in which the touch originally occurred. This object might not be the view the touch is currently in.

这个值的属性是发生触摸的视图对象。这个对象也许不是当前你触摸的那个你所看的视图

Availability

可用平台

Available in iPhone OS 2.0 and later.

可用于iPhone OS 2.0或者更新

See Also

同类参考

@property window

Declared In

定义文件

UITouch.h


window

The window in which the touch initially occurred. (read-only)

触摸事件初始发生的窗口。(只读)

@property(nonatomic, readonly, retain) UIWindow *window

Discussion

讨论

The value of the property is the window object in which the touch originally occurred. This object might not be the window the touch is currently in.

这个值是一个发生触摸事件的窗口对象。这个对象也许不是你所感觉触摸到的窗口。

Availability

可用平台

Available in iPhone OS 2.0 and later.

可用于iPhone OS 2.0或者更新

See Also

同类参考

@property view

Declared In

定义文件

UITouch.h


Instance Methods

实例方法


locationInView:

Returns the current location of the receiver in the coordinate system of the given view.

返回当前接收者在给定的视图坐标系中位置

- (CGPoint)locationInView:(UIView *)view

Parameters

参数

view

The view object in whose coordinate system you want the touch located. A custom view that is handling the touch may specify self to get the touch location in its own coordinate system. Pass nil to get the touch location in the window’s coordinates.

一个你想要转换过去的坐标系的视图对象。一个自定义的视图也许想要获取在自身坐标系中的触摸事件。传递nil将会获取基于窗口坐标系的触摸事件位置。

Return Value

返回值

A point specifying the location of the receiver in view.

在接收者view参数中定义的点的坐标

Discussion

讨论

This method returns the current location of a UITouch object in the coordinate system of the specified view. Because the touch object might have been forwarded to a view from another view, this method performs any necessary conversion of the touch location to the coordinate system of the specified view.

这个方法返回当前UITouch对象在指定的视图坐标系中的点的坐标。因为触摸对象也许是从其他视图转换到另一个视图,这个方法可以转换你给定的视图坐标系中的触摸的点的信息。

Availability

可用平台

Available in iPhone OS 2.0 and later.

可用于iPhone OS 2.0或者更新

See Also

同类参考

– previousLocationInView:

Related Sample Code

关联的例子代码

GLPaint

Metronome

MoveMe

oalTouch

PVRTextureLoader

Declared In

定义文件

UITouch.h

 


previousLocationInView:

Returns the previous location of the receiver in the coordinate system of the given view.

返回先前给定的视图坐标系中点坐标。

- (CGPoint)previousLocationInView:(UIView *)view

Parameters

参数

view

The view object in whose coordinate system you want the touch located. A custom view that is handling the touch may specify self to get the touch location in its own coordinate system. Pass nil to get the touch location in the window’s coordinates.

一个你想要转换过去的坐标系的视图对象。一个自定义的视图也许想要获取在自身坐标系中的触摸事件。传递nil将会获取基于窗口坐标系的触摸事件位置。

Return Value

返回值

This method returns the previous location of a UITouch object in the coordinate system of the specified view. Because the touch object might have been forwarded to a view from another view, this method performs any necessary conversion of the touch location to the coordinate system of the specified view.

这个方法返回先前的你所指定的视图坐标系中的UITouch对象的坐标。因为触摸对象也许是从其他视图转换到另一个视图,这个方法可以转换你给定的视图坐标系中的触摸的点的信息。

Availability

可用平台

Available in iPhone OS 2.0 and later.

可用于iPhone OS 2.0或者更新

See Also

同类参考

– locationInView:

Related Sample Code

关联的例子代码

GLPaint

PVRTextureLoader

Declared In

定义文件

UITouch.h


Constants

内容


Touch Phase

The phase of a finger touch.

触摸事件状态

typedef enum {
  UITouchPhaseBegan,
  UITouchPhaseMoved,
  UITouchPhaseStationary,
  UITouchPhaseEnded,
  UITouchPhaseCancelled,
} UITouchPhase;

Constants

UITouchPhaseBegan

A finger for a given event touched the screen.

一个触发触摸事件的手指

Available in iPhone OS 2.0 and later.

Declared in UITouch.h.


UITouchPhaseMoved

A finger for a given event moved on the screen.

一个手指触发屏幕移动事件

Available in iPhone OS 2.0 and later.

Declared in UITouch.h.


UITouchPhaseStationary

A finger is touching the surface but hasn't moved since the previous event.

一个手指触摸没有移动事件发生

Available in iPhone OS 2.0 and later.

Declared in UITouch.h.


UITouchPhaseEnded

A finger for a given event was lifted from the screen.

一个手指离开屏幕

Available in iPhone OS 2.0 and later.

Declared in UITouch.h.


UITouchPhaseCancelled

The system cancelled tracking for the touch, as when (for example) the user puts the device to his or her face.

系统取消跟踪触摸事件,比如当用户把电话放到靠近他的脸部时。

Available in iPhone OS 2.0 and later.

Declared in UITouch.h.

Discussion

讨论

The phase of a UITouch instance changes in a certain order during the course of an event. You access this value through the phase property.

UITouch实例对象的状态在事件的过程中不停的改变,你可以在phase属性中获取。

Declared In

UITouch.h

你可能感兴趣的:(UITouch)