ios - UIImageView touch handling -
i have image view background image. seeking in place on image view touches enabled. started this:
- (id)initwithtouchpoint:(cgrect )point { self = [super init]; if (self) { touchframe = point; [self setaccessibilityframe:touchframe]; } return self; } /* // override drawrect: if perform custom drawing. // empty implementation adversely affects performance during animation. - (void)drawrect:(cgrect)rect { // drawing code } */ -(bool)canresignfirstresponder{ return yes; } -(void)touchesbegan:(nsset *)touches withevent:(uievent *)event{ uitouch *touch = [[event alltouches] anyobject]; cgpoint touchlocation = [touch locationinview:self]; if (cgrectcontainspoint(touchframe, touchlocation)) { //[self setuserinteractionenabled:no]; }else{ //[self setuserinteractionenabled:yes]; } dlog(@"touchesbegan @ x : %f y : %f",touchlocation.x,touchlocation.y); } -(void)touchesmoved:(nsset *)touches withevent:(uievent *)event{ } -(void)touchesended:(nsset *)touches withevent:(uievent *)event{ }
is possible let user touch on image view when user touches in touchframe ?
thank you.
add uitapgesturerecognizer on uiimageview
uitapgesturerecognizer *gesture = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(handlegesture:)]; [gesture setnumberoftapsrequired:1]; [imageview setuserinteractionenabled:yes]; [imageview addgesturerecognizer:gesture];
now within handlegesture method :
-(void)handlegesture:(uitapgesturerecognizer *)_gesture { if (_gesture.state == uigesturerecognizerstateended) { cgpoint touchedpoint = [_gesture locationinview:self.view]; } }
you can check wether touchedpoint within handlegesture method in specified area or not , can perform desired task accordingly
Comments
Post a Comment