iOS Development--mkmapview Add Uipangesturerecognizer

Source: Internet
Author: User

When we wanted to add a drag gesture to Mkmapview, the first thought might be this:

-(void) viewdidload{    //....    Uipangesturerecognizer *pangesture = [[Uipangesturerecognizer alloc] initwithtarget:self action: @selector (Handlepan :)];    [Self.mapview addgesturerecognizer:pangesture];} -(void) Handlepan: (uipangesturerecognizer*) recognizer{    NSLog ("Handlepan");}
Running the program and then dragging the map, we will find that the console does not print any "handlepan", which means that the gesture recognition handler function Handlepan has never been executed. Later on the StackOverflow found the answer, the correct solution is as follows:

-(void) viewdidload{    //...       Uipangesturerecognizer *pangesture = [[Uipangesturerecognizer alloc] initwithtarget:self action: @selector (Handlepan :)];    Pangesture.delegate = self;    [Self.mapview addgesturerecognizer:pangesture];} -(BOOL) Gesturerecognizer: (Uigesturerecognizer *) Gesturerecognizer Shouldrecognizesimultaneouslywithgesturerecognizer: (Uigesturerecognizer *) Othergesturerecognizer {    return YES ;} -(void) Handlepan: (uipangesturerecognizer*) recognizer{    NSLog ("Handlepan");}

Compared with the previous two paragraphs, the latter program assigns the proxy to gesture recognition and implements the Shouldrecognizesimultaneouslywithgesturerecognizer proxy method.

Analyze the reason why the second code runs successfully: Mkmapview has added a uipangesturerecognizer when implemented internally, and here we have added another uipangesturerecognizer, This means that the same mkmapview has two gesture recognition of the same type, while the runtime internally defaults to the same type of gesture recognition only one will be processed, so the first piece of code always has no output handlepan. Fortunately uipangesturerecognizerdelegate provided the Gesturerecognizer:shouldrecognizesimultaneouslywithgesturerecognizer method, When this method returns Yes, it means that all gesture recognition of the same type will be processed.





iOS Development--mkmapview Add Uipangesturerecognizer

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.