IOS multi-point touch and gesture

Source: Internet
Author: User

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:

 
 
  1. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{  
  2.     NSUInteger numTouches = [touches count];  
  3. }  

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:

 
 
  1. -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{  
  2.     NSUInteger numTaps = [[touches anyObject] tapCount];  
  3. }  

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:

 
 
  1. -(Void) touchesbegan :( nsset *) touches withevent :( uievent *) event {
  2. If ([touches count] = 2) {// detect the number of touch points
  3. Nsarray * twotouches = [touches allobjects]; // obtain the touch point Array
  4. Uitouch * First = [twotouches objectatindex: 0]; // The first touch point
  5. Uitouch * Second = [twotouched objectatindex; 1]; // Second touch point
  6. Cgfloat initialdistance = distancebetweenpoints (
  7. [First locationinview: Self. View], [second locationinview: Self. View]); // calculates the distance between two touch points.
  8. }
  9. }

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.