Programming for long-pressed gesture events in iOS development

Source: Internet
Author: User

Long-press gesture event:

Long Press the button 1S to change the button color:

1 //Long Press Events2 #import "ViewController.h"3 @interfaceViewcontroller () {4UIButton *mybtn;5 }6 @end7 @implementationViewcontroller8- (void) Viewdidload {9 [Super Viewdidload];TenMYBTN = [[UIButton alloc]initwithframe:cgrectmake ( -, $,214, the)]; OneMybtn.backgroundcolor =[Uicolor Orangecolor]; A[Mybtn Settitle:@"Start button"Forstate:uicontrolstatenormal]; -Uilongpressgesturerecognizer *longpress = [[Uilongpressgesturerecognizer alloc]initwithtarget:self Action: @selector (longpressaction:)];//initialize a long-press gesture -[Longpress setminimumpressduration:1];//set how long to trigger events the[Mybtn addgesturerecognizer:longpress];//Add a long press gesture to the button - [Self.view addsubview:mybtn]; - } --(void) Longpressaction: (uilongpressgesturerecognizer*) sender{ + //Uigesturerecognizerstatepossible, various enumeration values for button state - //Uigesturerecognizerstatebegan, + //uigesturerecognizerstatechanged, A //uigesturerecognizerstateended, at //uigesturerecognizerstatecancelled, - //uigesturerecognizerstatefailed, - //uigesturerecognizerstaterecognized = uigesturerecognizerstateended -     if(Sender.state = =Uigesturerecognizerstatebegan) { -Mybtn.backgroundcolor = [Uicolor Greencolor];//triggers an event when the status is began (modifies the background color of the BTN) -     } in } - @end

Programming for long-pressed gesture events in iOS development

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.