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