iOS中的事件

About Events in iOS

Events are objects sent to an application to inform it of user actions. In iOS, events can take many forms: multitouch events, motion events—for example, from device accelerometers—and events for controlling multimedia. (This last type of event is known as a remote-control event because it originates from a headset or other external accessory.)

The UIKit and Core Motion frameworks are responsible for event propagation and delivery in iOS.

At a Glance

An Application Receives Multitouch Events When Users Touch its Views

The Multi-Touch interface of iPhones, iPads, and iPod touches generates low-level events when users touch views of an application. The application sends these events (as UIEvent objects) to the view on which the touches occurred. That view typically analyzes the touches represented by each event object and responds in an appropriate manner.

Applications are frequently interested in interpreting the touches a user makes as a common gesture, such as a tap or swipe gesture. These applications can make use of UIKit classes called gesture recognizers, each of which is designed to recognize a specific gesture.

An Application Receives Motion Events When Users Move the Device

Motion events come in different forms, and you can handle them using different frameworks. When users shake the device, the UIKit delivers a UIEvent object to an application; these shaking-motion events are gestures often used to trigger undo and redo actions. If you want your application to receive high-rate, continuous accelerometer and gyroscope data, use the Core Motion framework. (Only certain devices have a gyroscope.) You may also use the UIAccelerometer class to receive and handle accelerometer data.

Remote-Control Events Are Sent When Users Manipulate Multimedia Controls

By conforming to an Apple-provide specification, headsets and other external accessories can send (via the UIKit framework) remote-control events to an application capable of playing audio or video. The view hosting the multimedia can receive the events and thereby control the audio video according to the user’s command (for example, pausing or fast-forwarding).

How to Use this Book

Regardless of the type of event you’re interested in, you should first read “Event Types and Delivery.” This chapter provides essential background information.

See Also

Some iPhones and other devices have GPS and compass hardware that also generate low-level data delivered to an application for processing.Location Awareness Programming Guide discusses how to receive and handle this data.

Many sample code projects in the iOS Reference Library have code that illustrates the handling of multitouch events and the use of gesture recognizers. Among these are the following projects: TouchesMetronomeCopyPasteTile, and SimpleGestureRecognizers.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值