From: http://book.51cto.com/art/201110/297453.htm
4.2.2 IOS multi-point touch and gesture
IOS provided users with at least 3.5 inch broad perspectives, which was impressive at the time. On this stage, the fingers can beat flexibly. Before that, traditional touch-screen mobile phones can only use single fingers, and many of them are resistive screens. But since the advent of iOS, everything has changed.
1) multi-point touch
IOS has completely broken the traditional mobile phone operation mode, making it more user-friendly with multiple touch points. The implementation code of multi-touch is as follows:
- -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
- NSUInteger numTouches = [touches count];
- }
The above method passes an nsset instance and a uievent instance. You can obtain the object in the touches parameter to determine how many fingers are currently touched. Each object in the touches is a uitouch event, indicates that a finger is touching the screen. If the touch is a part of a series of clicks, you can also query related properties by asking any uitouch object.
Similar to mouse operations, IOS can also have click, double-click, or more similar operations. With these operations, more functions can be completed on this limited-size screen. As described above, you can access its touches attribute to query:
- -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
- NSUInteger numTaps = [[touches anyObject] tapCount];
- }
2) gestures
A gesture refers to all events that occur from one or more fingers touching the screen until the finger leaves the screen. No matter how long the process takes, as long as you have fingers on the screen, you are in a certain gesture, unless an unexpected situation occurs.
With a gesture, the screen can sense what action our hands are doing. In many cases, some controls have been able to support the double-finger open, zoom-in, and zoom-out actions. The multi-finger rotation function of images is flexible and convenient, and meets our living habits, such functions are the best proof that multi-finger technology is applied to reality. You can detect gestures in the following ways:
- -(Void) touchesbegan :( nsset *) touches withevent :( uievent *) event {
- If ([touches count] = 2) {// detect the number of touch points
- Nsarray * twotouches = [touches allobjects]; // obtain the touch point Array
- Uitouch * First = [twotouches objectatindex: 0]; // The first touch point
- Uitouch * Second = [twotouched objectatindex; 1]; // Second touch point
- Cgfloat initialdistance = distancebetweenpoints (
- [First locationinview: Self. View], [second locationinview: Self. View]); // calculates the distance between two touch points.
- }
- }
IPhone IOS 4. X allows you to enable screen zoom by setting: You can switch between the three fingers and press them twice. You can also move the screen by clicking the three fingers; you can resume the normal status after two connections.
The iPad IOS 4.3 supports four-finger operations. using various gestures, you can achieve many previously unfeasible effects: Four-finger slides can display programs running in the background; you can move the slider to the left to switch the opened program. If you move the slider to the right, you can switch the opened program to the right, the current program can be closed by means of kneading.