ios - Detect the Touch on the borders of an UIView -


i implementing image cropper, have circle area on top of image. area of image inside circle has cropped. have give scaling functionality cropping view. requirement have scale cropping view, when user touch on border of uiview , pan. cannot use pinch gesture. have attached image clear idea of requirement. can give optimised solution same.

enter image description here

i tried solution , got it.

viewcontroller.h

#import <uikit/uikit.h> @interface viewcontroller : uiviewcontroller @property (strong, nonatomic) iboutlet uiview *viewcircletouchpoint; @end 

viewcontroller.m

#import "viewcontroller.h"  @interface viewcontroller () {    float xvalue,yvalue; } @end @implementation viewcontroller @synthesize viewcircletouchpoint; 

now can use 2 option

first option:touch event method

according me when touch

- (void)viewdidload  {   [super viewdidload];   // additional setup after loading view, typically nib.    uigraphicsbeginimagecontext(viewcircletouchpoint.frame.size);   [[uiimage imagenamed:@"txnto.png"] drawinrect:viewcircletouchpoint.bounds];   uiimage *image = uigraphicsgetimagefromcurrentimagecontext();   uigraphicsendimagecontext();   viewcircletouchpoint.backgroundcolor = [uicolor colorwithpatternimage:image]; } 

according me when touch arrow part of view x value 168 , y value 50.so if less x , y value won't allow pan.if greater or equal set pan view.

-(void)touchesbegan:(nsset *)touches withevent:(uievent *)event {   uitouch *touch =[[event alltouches]anyobject];   cgpoint touchpoint = [touch locationinview:imagecirclepoint];   nslog(@"the border touch point - %@", nsstringfromcgpoint(touchpoint));   nslog(@"touch x :%f y: :%f",touchpoint.x,touchpoint.y);   xvalue =touchpoint.x;   yvalue =touchpoint.y;   if(xvalue>=168 && yvalue>=50){     uipangesturerecognizer *panrecognizer = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(pangesture:)];     [panrecognizer setminimumnumberoftouches:1];     [panrecognizer setmaximumnumberoftouches:1];     [viewcircletouchpoint addgesturerecognizer:panrecognizer];   } } 

now printed result is

enter image description here

second option:gesture reconizer

- (void)viewdidload {   [super viewdidload];   // additional setup after loading view, typically nib.     uigraphicsbeginimagecontext(viewcircletouchpoint.frame.size);   [[uiimage imagenamed:@"txnto.png"] drawinrect:viewcircletouchpoint.bounds];   uiimage *image = uigraphicsgetimagefromcurrentimagecontext();   uigraphicsendimagecontext();   viewcircletouchpoint.backgroundcolor = [uicolor colorwithpatternimage:image];     uitapgesturerecognizer *tapgesture =[[uitapgesturerecognizer alloc]initwithtarget:self action:@selector(tapdetected:)];   tapgesture.numberoftouchesrequired=1;   viewcircletouchpoint.userinteractionenabled = yes;   [viewcircletouchpoint addgesturerecognizer:tapgesture]; }  -(void)tapdetected:(uitapgesturerecognizer *)gesture {   cgpoint point = [gesture locationinview:imagecirclepoint];   nslog(@"the border touch point - %@", nsstringfromcgpoint(point));   nslog(@"touch x :%f y: :%f",point.x,point.y);   if(point.x>=168 && point.y>=50){     uipangesturerecognizer *panrecognizer = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(pangesture:)];     [panrecognizer setminimumnumberoftouches:1];     [panrecognizer setmaximumnumberoftouches:1];     [viewcircletouchpoint addgesturerecognizer:panrecognizer];   } }  -(void)pangesture:(uipangesturerecognizer *)gesturepan {    nslog(@"the pan gesture recognizer called");    .....//do stuff here } 

the printed result tap

enter image description here

see iphone tried screenshot below.i did not add imageview view.

enter image description here


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -