Draw beautiful diagram effortlessly on ipad. Click here to know more..

Saturday, February 2, 2013

Touch gestures in iOS (iPhone, iPad) sdk

iOS sdk provides simple and powerful touch gesture API. With few lines of code, you can make your app touch/multitouch aware.
In this blog post, I am posting code snippet for using touch gesture in iOS app. The code snippet is taken from a drawing app: Lekh Diagram
The Lekh Diagram heavily uses touch gestures. Here are touch gestures used by Lekh Diagram

  • pan
  • two finger drag
  • tap
  • double tap
  • long press
  • pinch
  • rotate
All these gestures are used in the app on the drawing canvas. The Lekh Diagram registers and handles all multitouch events except "two finger drag". The two finger drag is handled by UIScrollView. 

Here is code snippet for registering gesture events:

The Lekh Diagram has drawing canvas which derives from UIView as
@interface DrawingView : UIView
@end

In the constructer of this class, following code registers for events.

// *******************************************************************
    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc
                                          initWithTarget:self action:@selector(handlePanGesture:)];
    panGesture.minimumNumberOfTouches = 1;
    panGesture.maximumNumberOfTouches = 1;
    [self addGestureRecognizer:panGesture];
    

// ****************************************************************
    UITapGestureRecognizer *doubleTap = 
    [[UITapGestureRecognizer alloc]
     initWithTarget:self action:@selector(handleDoubleTapGesture:)];
    [doubleTap setNumberOfTapsRequired:2];
    [self addGestureRecognizer:doubleTap];
    

// ****************************************************************
    UITapGestureRecognizer *tapGest = 
    [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
    [tapGest requireGestureRecognizerToFail:doubleTap];
    [self addGestureRecognizer:tapGest];
    

// *******************************************************************
    UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
    longPressGesture.minimumPressDuration = 1;
    [self addGestureRecognizer:longPressGesture];
    

// *********************************************************************
    UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handleZoom:)];
[self addGestureRecognizer:pinchRecognizer];
    
// *******************************************************************
    UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotate:)];
[self addGestureRecognizer:rotationRecognizer];


Here are event handler functions

-(IBAction)handleLongPress:(UILongPressGestureRecognizer*)sender{  
    if(UIGestureRecognizerStateBegan == sender.state) {
     // long press handler code
   }
}

-(IBAction)handleRotate:(UIRotationGestureRecognizer*)sender{
  if([sender state] == UIGestureRecognizerStateEnded) {
     // handler code for rotation end

   }

    else if([sender state] == UIGestureRecognizerStateBegan){

       // handler code for rotation start
    }
    else{
        double rotation = [sender rotation]; // amount of rotation
        // handler code for rotation in progress
    }

}

-(IBAction)handleZoom:(UIPinchGestureRecognizer*)sender{
    if([sender state] == UIGestureRecognizerStateEnded) {
        // handler code for pinch end
    }
    else if([sender state] == UIGestureRecognizerStateBegan){
      // handler code for pinch start
    }
    else{
        CGFloat scale = [(UIPinchGestureRecognizer*)sender scale]; // amount of pinch
       // handler code for pinch progress
    }

}

-(IBAction)handlePanGesture:(UIPanGestureRecognizer *)sender{
     CGPoint location = [sender locationInView:self];  // current touch position
      if(sender.state == UIGestureRecognizerStateEnded){
        // handler code for panning end
      }
      else if(sender.state == UIGestureRecognizerStateBegan){
         // handler code for panning starts
      }
      else {
         // handler code for panning in progress
      }

}

- (IBAction)handleTapGesture:(UIGestureRecognizer *)sender {
    CGPoint location = [sender locationInView:self]; // tap location
   // handler code for tap
}

- (IBAction)handleDoubleTapGesture:(UIGestureRecognizer *)sender {
    CGPoint location = [sender locationInView:self]; // double tap location
    // handler code for double tap
}




Here is demo of Lekh Diagram, you can see touch gesture in action in this video




65 comments:

  1. Thankful such an awesome sum for sharing this glorious information! I am envisioning see more posts by you. I like visiting you site since I always come across interesting articles like this one. Great Job, I greatly appreciate that. Do keep sharing! Your information is good and friendly this article very helpful for me. Thanks for the post. After seeing the following post, I totally inspire from you and your blogs also respectively. It was nice articles and I also very enjoyed after read this. Thanks a lot sir. Visit here also: Best essay writing service

    ReplyDelete
  2. I actually never even though about getting deeper into my iPad settings to get some extra features working properly. I usually use my iPad for music, books and essay paper writing services so I never even bother. Thank you for sharing.

    ReplyDelete
  3. I discovered your this post while hunting down data about web journal related exploration ... It's a decent post .. continue posting and overhauling data. Tax Enquiry Accounts

    ReplyDelete
  4. Much obliged to you again for all the information you distribute,Good post. I was exceptionally keen on the article, it's entirely rousing I ought to concede. I like going to you site since I generally run over fascinating articles like this one.Great Job, I incredibly acknowledge that.Do Keep sharing! Respects, HMRC Tax Investigation Accountants

    ReplyDelete
  5. I am constantly stunned by the measure of data accessible on this subject. What you exhibited was very much explored and eloquent so as to get your stand on this crosswise over to every one of your perusers. Tax Enquiry

    ReplyDelete
  6. On the off chance that more individuals that compose articles truly fretted about composing incredible substance like you, more perusers would be occupied with their works. Much obliged to you for thinking about your substance. Let Campaign Tax Enquiry

    ReplyDelete
  7. There are actually lots of particulars like that to take into consideration. That may be a nice level to bring up. I provide the ideas above as general inspiration but clearly there are questions just like the one you convey up the place a very powerful thing will probably be working in sincere good faith. I don?t know if greatest practices have emerged round issues like that, but I’m sure that your job is clearly recognized as a good game. Both boys and girls feel the impression of just a moment’s pleasure, for the rest of their lives. Tax Investigation Self Employed

    ReplyDelete
  8. I think this is one of the most significant information for me. And i’m glad reading your article. But should remark on some general things, The web site style is perfect, the articles is really great : D. Good job, cheers Let Campaign Tax Enquiry Accountants

    ReplyDelete
  9. Much obliged to you for some other educational online journal. Where else would I be able to understand that kind of data written in such a perfect means? I have a mission that I"m a few seconds ago taking a shot at, and I have been at the post for such data. Let Property Campaign

    ReplyDelete
  10. I am upbeat to discover this post exceptionally helpful for me, as it contains part of data. I generally want to peruse the quality substance and this thing I found in you post. A debt of gratitude is in order for sharing. Let Property Campaign Accountants

    ReplyDelete
  11. Howdy! Pleasant stuff, do update me as often as possible when you post again something like this! Buy to Let Property Tax Advisors

    ReplyDelete
  12. I as of late discovered numerous helpful data in your site particularly this online journal page. Among the loads of remarks on your articles. A debt of gratitude is in order for sharing. Buy to Let Property Tax Advice

    ReplyDelete
  13. I've been hunting down some better than average stuff on the subject and haven't had any fortunes up until this point, You just got another greatest fan!.. backlinks service

    ReplyDelete
  14. It is an extraordinary site.. The Design looks great.. Continue working like that!. high DA backlinks

    ReplyDelete
  15. A debt of gratitude is in order for the pleasant site. It was extremely helpful for me. I'm cheerful I discovered this online journal. Much obliged to you for offering to us,I too dependably gain some new useful knowledge from your post. Buy to Let Tax Advisor

    ReplyDelete
  16. Incredible review, I'm certain you're getting an extraordinary reaction. Buy to Let Property Tax Advice London

    ReplyDelete
  17. This is an awesome motivating article.I am practically satisfied with your great work.You put truly extremely supportive data. Keep it up. Continue blogging. Hoping to perusing your next post. Property Tax Accountant

    ReplyDelete
  18. I truly like you're composing style, awesome data, thankyou for posting. Property Tax Advice

    ReplyDelete
  19. Much obliged you all that much to share these connections. Will look at this.. Property Tax Advisors

    ReplyDelete
  20. This is such an incredible asset, to the point that you are giving and you give it away for nothing. I cherish seeing blog that comprehend the quality. Im happy to have discovered this post as its such a fascinating one! I am dependably vigilant for quality posts and articles so i assume im fortunate to have discovered this! I trust you will be including more later on... Tax on Buy to Let Property

    ReplyDelete
  21. Awesome things you've generally imparted to us. Simply continue composition this sort of posts.The time which was squandered in going for educational cost now it can be utilized for studies.Thanks Tax Investigation Self Assessment

    ReplyDelete
  22. This is my first time visit here. From the huge amounts of remarks on your articles,I surmise I am not just one having all the delight right here! Tax Investigation Specialists

    ReplyDelete
  23. I felt exceptionally cheerful while perusing this site. This was truly extremely instructive site for me. I truly loved it. This was truly a welcoming post. Much appreciated!. Tax Investigation Self Employed

    ReplyDelete
  24. Great article, much obliged for assembling this! This is clearly one extraordinary post. A debt of gratitude is in order for the important data and bits of knowledge you have so given here. Tax Investigation Accountants

    ReplyDelete
  25. This is extremely fascinating substance! I have completely delighted in perusing your focuses and have arrive at the conclusion that you are right about a number of them. You are incredible. blog comments backlinks

    ReplyDelete
  26. Okay, let's be honest here - I'm a huge procrastinator and I've started worrying about my final essay only a few days before the deadline. I understood that I was screwed, so I've decided to ask for help at this essay writing service. And these guys just saved my life!

    ReplyDelete
  27. A debt of gratitude is in order for setting aside an ideal opportunity to talk about this, I feel emphatically about it and affection adapting more on this theme. On the off chance that conceivable, as you pick up skill, would you brain overhauling your online journal with additional data? It is to a great degree accommodating for me. Profile backlinks

    ReplyDelete
  28. Are you a freelance writer, novelist, or short story writer? If so, join our writing community with
    cash prize contests, freelance opportunities, and free writing tools. https://gurudissertation.net/dissertation-editing/

    ReplyDelete
  29. papernow.org
    Your essay service is a unique custom essay writing services. I got a paper that was top-quality, and ever since, I've not been able to stop talking about what you do, and how well you do it! Your customer service was equally excellent.

    ReplyDelete
  30. Almost everyone has access to the Internet today. Most people use social networks, online cinemas and other services, recently online casinos have also been added to their number. If you are interested in online casinos, then visit best free pokies.

    ReplyDelete
  31. My sister and I are really grateful to this sdk for ios. She was looking for this for a couple of nights and really frustrated that haven't seen any of like this before. Now she is happy. I am here now and would just like to say thanks a lot for a lucky post and we hope that you can help out a lot of people like my sister! If you are looking for a game - akinator! the web genie! you should try this game! Really amazing that the genie knows what I was thinking. If you dont belive me you can visit and play the game (go url)

    ReplyDelete
  32. Stock Exchange Securities Market Software

    Stock analysis software won't make you an investment pro overnight, but it can improve your success in the market, whether you're a long-term investor or a day trader.

    ReplyDelete
  33. SaaS Management Software

    SaaS management is the business practice of proactively monitoring and managing the purchasing, onboarding, licensing, renewals, and offboarding of all the software-as-a-service (SaaS) applications within a company’s technology portfolio.

    Developed in response to the unique attributes of SaaS applications in a business environment, SaaS management is quickly developing into a specialized practice for IT, Procurement, and business leaders.

    ReplyDelete
  34. Loan origination software

    A Loan Origination System (LOS) is a set of software built to support the processing and application process during a mortgage life cycle. It allows lenders & loan officers to easily submit and retrieve data, loan processors to process and index information easily and meets the needs of financial institutions that pull reports and validate personal information.

    It essentially connects the dots digital of many manual process that used to be very time consuming. Saving time for all of the many parties involved in the mortgage process.

    ReplyDelete
  35. Manufacturing Software

    Various types of software are used by manufacturing industries, such as product development process (PDP) software, product data management (PDM) software, product life-cycle management (PLM) software, enterprise resource planning (ERP) software, computer-aided design (CAD) software, computer-aided manufacturing (CAM)

    ReplyDelete
  36. Event management platforms

    An event management system is typically made up of client agents that reside in the remote devices, a central component for gathering the events, an event database and a reporting system to deliver the results in various formats. See service level management system and application management system.

    ReplyDelete
  37. https://cracksoon.com/wavepad-crack-registration-code-download/
    Cracked Here is a useful place where you can easily find Activators, Patch, Full version software Free Download, License key, serial key, keygen, Activation Key and Torrents.
    Get all of these by easily just on a single click.

    ReplyDelete
  38. https://hmzapc.com/flixgrab-crack-with-serial-key/
    FlixGrab+ License Key highly respects the copyright terms. Where it also unacceptable the limitation rules of sources. So, the software did not follow the law in already purchase free content. There is no limit boundary for FlixGrab establish by Netflix and video services. Where the allows legally to download videos from services. Which is just only allows for personal use. Therefore the user not right to share it with the third party.

    ReplyDelete
  39. Hello! Its interesting, thanks
    I have been trading forex for 5 years. You can find the best momentum trading strategies here.

    ReplyDelete
  40. cardrecovery key generator
    CardRecovery Serial Key is very easy to use. The whole restoration technique consists of several stages. First, you must select the card you want to use to repair the document, the file you want to find, and select the location of the recovered document. The program then scans the card and publishes a list of files it finds. With the preview function, you can easily find and retrieve your photos and movies. Nikon NEF, Canon CRW, and CR2, Kodak DCR, Konica Minolta MRW, Fuji RAF, Sigma X3F, Sony SRF, Samsung DNG, Pentax PEF, It also supports Ross documents, including Olympus ORF, Leica DNG, Panasonic RAW, and more. We support CardRecovery Downloads because it’s easy, secure and fast.

    ReplyDelete
  41. Hi! thanks for this info. Are you familiar with the ExpertOption App? You can find expertoption login page here.

    ReplyDelete
  42. Through www.amazon.com/mytv - how you can connect your mobile phone to Amazon Prime. Through amazon.com/mytv, you can watch your favorite TV shows, series movies. You can watch prime videos anywhere on your device. Users need to create an Amazon account if they don’t have an Amazon account and enter the Amazon my TV activation code to watch Amazon prime videos on your device.

    amazon.com/mytv | www.amazon.com/mytv

    ReplyDelete
  43. my name is julietta i am the feline here at otacal. com i'm probably the only tortie in the room and am almost always the one who is most vocal.

    https://onlineslotsx.com/free-slots/buffalo/ i tend to get confused with the vocal Bichons and sometimes get a little too vocal myself.

    ReplyDelete
  44. The Panspermia was being sucked into a black hole https://free-onlinepokies.com/vendor/aristocrat/
    that appeared from nowhere!

    Angela was awake again.

    ReplyDelete
  45. RogueKiller Crack
    RogueKiller Serial Key provides comprehensive data on your computer infections. In this way, depending on the structure of your computer, you can save tissue or disconnected infections. There are also other powerful functions, such as searching for geographic and symbolic landmarks. Requires the use of any computer chassis. Another application for malware programming.
    https://crackphilia.com/

    ReplyDelete
  46. Thanks for sharing such an amazing content. Really loved to read such content. Keep posting such content in future as well.
    Disk Drill Pro Crack
    DVDFab Crack
    ESET NOD32 Antivirus Crack
    DAEMON Tools Pro Crack
    Final Cut Pro Crack

    ReplyDelete
  47. I really love your work it’s very beneficial to many people’s. Your blog approach helps many people like myself. Its content is very easy to understand and helps a lot,
    Do visit my site for new and Updated software :u!
    DxO PhotoLab Mac Crack
    PhotoSweeper X Mac Crack
    MacCleanse Crack
    FileZilla Pro Crack
    Yamicsoft Windows 10 Manager Crack
    Sonic Mania PC Crack
    Connectify Hotspot Pro Crack
    Google Nik Collection Crack
    IDM Crack

    ReplyDelete
  48. Thanks for sharing such an amazing content. Really loved to read such content. Keep posting such content in future as well.
    HD Video Converter Crack
    FileZilla Pro Crack
    Adobe Photoshop CC Crack
    5KPlayer Crack

    ReplyDelete
  49. Thanks for sharing such an amazing content. Really loved to read such content. Keep posting such content in future as well.
    ESET NOD32 Antivirus Crack
    iMazing Crack
    Avocode Crack
    GlassWire Crack

    ReplyDelete
  50. Thanks for sharing such an amazing content. Really loved to read such content. Keep posting such content in future as well.
    Wise Care 365 Pro Crack
    Visual Studio Code Crack
    Thunderbird Crack
    GOM Player Plus Crack
    REAPER Crack

    ReplyDelete
  51. I really love your work it’s very beneficial to many people’s. Your blog approach helps many people like myself. Its content is very easy to understand and helps a lot,
    Do visit my site for new and Updated software:
    Visual Studio Code Crack
    Softros LAN Messenger Crack
    Brave Browser Crack
    MacCleanse Crack
    REAPER Crack
    LinkAssistant Crack
    Debut Video Capture Crack
    PureVPN crack

    ReplyDelete
  52. I really love your work it’s very beneficial to many people’s. Your blog approach helps many people like myself. Its content is very easy to understand and helps a lot,
    Do visit my site for new and Updated software:

    LinkAssistant Crack
    Debut Video Capture Crack
    PureVPN crack
    ActivePresenter Crack
    Artweaver Plus crack

    ReplyDelete
  53. I really love your work it’s very beneficial to many people’s. Your blog approach helps many people like myself. Its content is very easy to understand and helps a lot,
    Do visit my site for new and Updated software:

    Bitwarden Password Manager crack
    Kaspersky Security Cloud crack
    Folx Pro Crack
    KeyShot Pro crack
    Macrium Reflect crack
    Glitch 2 VST crack
    7-Zip Crack

    ReplyDelete
  54. I really love your work it’s very beneficial to many people’s. Your blog approach helps many people like myself. Its content is very easy to understand and helps a lot,
    Do visit my site for new and Updated software:

    iMazing Crack
    FxFactory Pro Crack
    Metasploit Pro Crack
    Source Insight Mac Crack
    Sparkle Pro Crack
    Vivaldi Browser crack
    World of Tanks WoT crack
    MATLAB R2022a crack
    Metasploit Pro Crack
    Source Insight Crack

    ReplyDelete
  55. Tor Browser Mac Crack
    Tor Browser is free web browsing software and an open network. It helps you defend against traffic analysis, a form of network surveillance that threatens personal freedom and privacy, business relationships and confidential activities, and state security. Tor Browser protects you by returning your communications over a distributed network of broadcasts led by volunteers from around the world.
    https://masabtech.com/

    ReplyDelete
  56. I am happy after visited this site. It contains valuable data for the guests. Much thanks to you!
    License Key Download
    DiskDigger Crack
    MikroTik Crack
    ProShow Producer Crack
    Speccy Pro Crack

    ReplyDelete
  57. Wszystkim miłośnikom emocji proponuję grę w kasynie online. Tutaj od razu otrzymasz świetne bonusy. Możesz grać z dowolnego gadżetu, co http://nastrychu.com.pl/ 22bet pl jest bardzo wygodne. Interfejs jest przejrzysty, więc nie będzie problemów. W wolnym czasie bawię się i cieszę się resztą. Dołącz teraz!

    ReplyDelete
  58. You have hundreds of online brokers to choose from, so we are here to help you make an informed decision. Brokers That Accept Webmoneyprovides many resources including a comparison system based on the top brokers in the industry, Brokers Review And There Login Details to help you find the one that is best for you.

    ReplyDelete
  59. At Ic Market, We Are Dedicated To Providing You With Reviews Based On Real Experience. Our Team Conducts Extensive Research And Tests Each Strategy We Review To Make Sure That You Get The Satisfaction Guarantee That You Deserve!

    ReplyDelete
  60. We provide students with well structured, properly organized, and neatly connected reports in any required. where can i buy assignments

    ReplyDelete
  61. English essay assignments used to be overwhelming for me, but now I can easily get essay helper online. Their essay writers are experienced and knowledgeable in English, offering me customized solutions for my assignments. Their essay writing tutor has been instrumental in enhancing my essay writing skills.

    ReplyDelete