ios - Tap Gesture does not always work -



ios - Tap Gesture does not always work -

i have nsobject instantiate view uitapgesturerecognizer added. goes wrong because tap works sometimes...

#import "monument.h" @implementation monument -(id)initwithframe:(cgrect)frame itiname:(nsstring *)itiname itipay:(bool)itipay available:(bool)available imagename:(nsstring *)imagename viewcontroller:(uiviewcontroller *)controller { self = [super init]; if (self) { self.view = [[uiview alloc] initwithframe:frame]; self.view.userinteractionenabled = yes; self.itiname = itiname; self.itipay = itipay; self.itiimage = imagename; self.controller = controller; nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; if (! [defaults boolforkey:itiname]) { self.buy = no; } else { self.buy = yes; } self.x = frame.origin.x; self.y = frame.origin.y; self.available = available; } homecoming self; } -(uiview *)drawview { uiimage *background = [uiimage imagenamed:self.itiimage]; uiimageview *backgroundview = [[uiimageview alloc] initwithimage:background]; backgroundview.frame = self.view.frame; backgroundview.contentmode = uiviewcontentmodescaleaspectfit; [self.view addsubview:backgroundview]; // inzializzo la label del titolo uilabel *titolo = [[uilabel alloc] initwithframe:cgrectmake(self.x+8.0f, self.y+2.0f, 180.0f, 20.0f)]; titolo.text = self.itiname; titolo.textcolor = [uicolor whitecolor]; [self.view addsubview:titolo]; uiimage *imagefreeorpayorbought; if (! self.buy) { if (self.itipay) { imagefreeorpayorbought = [uiimage imagenamed:@"pay-ipad"]; } else { imagefreeorpayorbought = [uiimage imagenamed:@"free-ipad"]; } } else { // giĆ  comprato imagefreeorpayorbought = [uiimage imagenamed:@"free-ipad"]; } uiimageview *payorfree = [[uiimageview alloc] initwithimage:imagefreeorpayorbought]; cgrect frameimage = cgrectmake(self.x, self.y+117.0f, 214.5f, 20.8f); payorfree.frame = frameimage; payorfree.contentmode = uiviewcontentmodescaleaspectfit; [self.view addsubview:payorfree]; // controllo se disponibile o meno if (! self.available) { self.view.layer.opacity = .3f; } uitapgesturerecognizer *tap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(taprecognized:)]; [self.view addgesturerecognizer:tap]; homecoming self.view; } -(void)taprecognized: (uitapgesturerecognizer *)tap { if (! self.available) { // [self openunavailableservice]; nslog(@"service unavailable"); } else { if (self.buy) { //[self openmonumenthomepage]; nslog(@"service bought"); } else { if (self.itipay) { //[self openpurchaseinapp]; nslog(@"service buy"); } else { //[self downloaddataforfree]; nslog(@"service free download"); } } } }

and that's how utilize class

self.arrayofmonuments = [[nsmutablearray alloc] init]; self.scroll.contentsize = cgsizemake(568.0f, 640.0f); monument *fororomano = [[monument alloc] initwithframe:cgrectmake(20.0f, 0.0f, 217.1f, 117.0f) itiname:@"foro romano" itipay:no available:yes imagename:@"fori-romano-ipad" viewcontroller:self]; [self.arrayofmonuments addobject:fororomano]; uiview *fororomanoview = [fororomano drawview]; [self.scroll addsubview:fororomanoview]; monument *colosseo = [[monument alloc] initwithframe:cgrectmake(150.0f, 0.0f, 217.1f, 117.0f) itiname:@"colosseo" itipay:no available:yes imagename:@"colosseo-ipad" viewcontroller:self]; [self.arrayofmonuments addobject:colosseo]; [self.scroll addsubview:[colosseo drawview]]; monument *appiaantica = [[monument alloc] initwithframe:cgrectmake(20.0f, 80.0f, 217.1f, 117.0f) itiname:@"appia antica" itipay:yes available:no imagename:@"appia-antica-ipad" viewcontroller:self]; [self.arrayofmonuments addobject:appiaantica]; uiview *appiaanticaview = [appiaantica drawview]; [self.scroll addsubview:appiaanticaview]; monument *esquilino = [[monument alloc] initwithframe:cgrectmake(150.0f, 80.0f, 217.1f, 117.0f) itiname:@"esquilino" itipay:yes available:no imagename:@"esquilino-ipad" viewcontroller:self]; [self.arrayofmonuments addobject:esquilino]; [self.scroll addsubview:[esquilino drawview]]; monument *palatino = [[monument alloc] initwithframe:cgrectmake(20.0f, 160.0f, 217.1f, 117.0f) itiname:@"palatino" itipay:yes available:no imagename:@"palatino-ipad" viewcontroller:self]; [self.arrayofmonuments addobject:palatino]; [self.scroll addsubview:[palatino drawview]]; monument *laterano = [[monument alloc] initwithframe:cgrectmake(150.0f, 160.0f, 217.1f, 117.0f) itiname:@"laterano" itipay:yes available:no imagename:@"laterano-ipad" viewcontroller:self]; [self.arrayofmonuments addobject:laterano]; [self.scroll addsubview:[laterano drawview]]; monument *foriimperiali = [[monument alloc] initwithframe:cgrectmake(20.0f, 240.0f, 217.1f, 117.0f) itiname:@"fori imperiali" itipay:yes available:no imagename:@"fori-imperiali-ipad" viewcontroller:self]; [self.arrayofmonuments addobject:foriimperiali]; [self.scroll addsubview:[foriimperiali drawview]];

how can happens? lot

edit: tried replacee uitapgesture uibutton, problem still presents

uibutton *monumentbtn = [[uibutton alloc] initwithframe:self.view.frame]; monumentbtn.backgroundcolor = [uicolor clearcolor]; [self.view addsubview:monumentbtn]; [monumentbtn addtarget:self action:@selector(taprecognized:) forcontrolevents:uicontroleventtouchupinside];

edit: noticed x/y coordinates pass init method wrong because first frame's height 117.0f , view positioned under has 80.0f y origin. that's strange, , that's why tap not work. how can solve issue?

re-edit: solved mapping of screen...unfortunately didn't find other solutions.

ios uigesturerecognizer uitapgesturerecognizer tap

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -