multiple errors trying to use UIGesture objective c iOS -
i'm trying create view in app button if tapped 3 times happens. have looked @ multiple questions , used multiple codes cannot work. code:
#import "viewcontroller3.h" #import <avfoundation/avfoundation.h> #import "viewcontroller.h" @interface viewcontroller3 () { avaudioplayer *_player; } @end @implementation viewcontroller3 - (void)viewdidload { [super viewdidload]; nsstring *path = [nsstring stringwithformat:@"%@/sound.m4a", [[nsbundle mainbundle] resourcepath]]; nsurl *soundurl = [nsurl fileurlwithpath:path]; _alarmplayer.numberofloops = -1; _alarmplayer = [[avaudioplayer alloc] initwithcontentsofurl:soundurl error:nil]; [ _player play]; uitapgesturerecognizer *tapgesture = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(handletapgesture:)]; uievent *event; uitouch *touch = [[event alltouches] allobjects]; //warning tapgesture.numberoftapsrequired = 3; [self.view addgesturerecognizer:tapgesture]; } - (void)handletapgesture:(uitapgesturerecognizer *)sender { if (sender.state == uigesturerecognizerstaterecognized) { // handling code } } - (ibaction)iconsbtn:(id)sender { if(touch.tapgesture) = 3) { //errors 1 , 2 [ _alarmplayer stop]; } else nslog(@"ughhhhh"); }
warning:
- incompatible pointer types initializing 'uitouch *' expression of type 'nsarray *'
errors:
- use of undeclared identifier 'touch'
- expected expression
how rid of errors , function correctly?
thanks!
also if wants mark me down please comment explain why can learn it.
try use these..
write these in viewdidload..
uitapgesturerecognizer *tapgesture = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(handletapgesture:)]; tapgesture.numberoftapsrequired = 3; [self.view addgesturerecognizer:tapgesture];
here in above code addgesturerecognizer wants perform 3 taps..
modify handletapgesture these..
-(void)handletapgesture:(uitapgesturerecognizer*)gesture { [ _alarmplayer stop]; }
remove these..
- (ibaction)iconsbtn:(id)sender { if(touch.tapgesture) = 3) { //errors 1 , 2 [ _alarmplayer stop]; } else nslog(@"ughhhhh"); }
or
check these too..
write these in viewdidload..
uibutton *btnsss=[[uibutton alloc]initwithframe:cgrectmake(10, 200, 60, 64)]; [btnsss setbackgroundcolor:[uicolor redcolor]]; [self.view addsubview:btnsss]; uitapgesturerecognizer *tapgesture = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(handletapgesture:)]; tapgesture.numberoftapsrequired = 3; [btnsss addgesturerecognizer:tapgesture];
here when tap 3 times on button below method called..
-(void)handletapgesture:(uitapgesturerecognizer*)gesture { nslog(@"hello"); [ _alarmplayer stop]; }
i hope helps..
Comments
Post a Comment