ios - How to increase the size and height of view by dragging the view from the corners in UITapGestureRecognizer in iphone? -


i doing project in have show 1 image, when click on image 1 "white view "will come on upper side of image. , when double click on "two pins" come out on "white view". when pull these 2 pins width , height of white view increase , decrease.

i not able this.

any idea experts highly welcome.

second_view.h file  #import <uikit/uikit.h>  @interface second_view : uiviewcontroller<uigesturerecognizerdelegate>{   uitapgesturerecognizer *tap; uiswipegesturerecognizer *swipe; uipangesturerecognizer *pan; cgpoint startlocation; cgfloat lastscale; cgfloat firstx; cgfloat firsty; cgpoint lastlocation;   uiimageview *imagevw; }   @property (nonatomic)  cgpoint center;  @property (nonatomic)  nsinteger count;  @property(nonatomic,retain) uiimageview *imagevw;   @end   second_view.m file - (void)viewdidload { [super viewdidload]; // additional setup after loading view. self.view.backgroundcolor = [uicolor graycolor];  imagevw = [[uiimageview alloc]initwithframe:cgrectmake(200, 200, 500, 400)]; imagevw.image = [uiimage imagenamed:@"redacted2.jpg"]; imagevw.userinteractionenabled=yes; imagevw.autoresizessubviews = yes; imagevw.alpha = 0.93;  // opacity [self.view addsubview:imagevw];     tap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(handletap:)]; tap.numberoftapsrequired = 1; [imagevw addgesturerecognizer:tap]; tap.delegate=self; pan=[[uipangesturerecognizer alloc]initwithtarget:self action:@selector(panaction:)]; [pan setminimumnumberoftouches:1]; [pan setmaximumnumberoftouches:2]; [pan setdelegate:self]; count=0; [imagevw addgesturerecognizer:pan];    }   - (void)panaction:(uipangesturerecognizer *)gesturerecognizer { cgpoint translatedpoint = [(uipangesturerecognizer*)gesturerecognizer        translationinview:self.view];  if ([(uipangesturerecognizer*)gesturerecognizer state] ==     uigesturerecognizerstatebegan) { firstx = [[gesturerecognizer view] center].x; firsty = [[gesturerecognizer view] center].y; }   translatedpoint = cgpointmake(firstx+translatedpoint.x, firsty+translatedpoint.y);  [[gesturerecognizer view] setcenter:translatedpoint];  if ([(uipangesturerecognizer*)gesturerecognizer state] ==   uigesturerecognizerstateended) { cgfloat velocityx = (0.2*[(uipangesturerecognizer*)gesturerecognizer     velocityinview:self.view].x);   cgfloat finalx = translatedpoint.x + velocityx; cgfloat finaly = firsty;// translatedpoint.y + (.35*[(uipangesturerecognizer*)sender    velocityinview:self.view].y);  if (uideviceorientationisportrait([[uidevice currentdevice] orientation])) { if (finalx < 0) { //finalx = 0; } else if (finalx > 768) { //finalx = 768; }  if (finaly < 0) { finaly = 0; } else if (finaly > 1024) { finaly = 1024; } } else { if (finalx < 0) { //finalx = 0; } else if (finalx > 1024) { //finalx = 768; }  if (finaly < 0) { finaly = 0; } else if (finaly > 768) { finaly = 1024; } } } }     -(void)handletap:(uipangesturerecognizer *)gesturerecognizer {  cgpoint location = [gesturerecognizer locationinview:gesturerecognizer.view]; nslog(@"x:%f y:%f",location.x,location.y);   nsarray *subviewsofimage = [imagevw subviews];   (id subview in subviewsofimage) { cgrect frame1=[subview frame]; int x=0; int y=0; x=frame1.origin.x+frame1.size.width; y=frame1.origin.y+frame1.size.height;  if ((location.x>=frame1.origin.x && location.x<x) && (location.y>=frame1.origin.y &&   location.y<y) ) { nslog(@"no"); return; } }   derivedview *view=[[derivedview alloc]initwithframe:cgrectmake(location.x, location.y, 100, 30)]; [view setbackgroundcolor:[uicolor whitecolor]]; [imagevw addsubview: view]; nsarray * subviewsofimage1 = [imagevw subviews]; nslog(@"subviewsofimage = %@",subviewsofimage1); nslog(@"yes");  } 

derivedview.h file

#import <uikit/uikit.h>  @interface derivedview : uiview<uigesturerecognizerdelegate> { uipangesturerecognizer *pan; uitapgesturerecognizer *tap1; uitapgesturerecognizer *tap2; uitapgesturerecognizer *tap3; cgpoint lastlocation; cgfloat firstx; cgfloat firsty; uiimageview *rpinimgview; uiimageview *lpinimgview;  }  @end 

derivedview.m file

- (id)initwithframe:(cgrect)frame { self = [super initwithframe:frame];  if (self) { // initialization code pan=[[uipangesturerecognizer alloc]initwithtarget:self action:@selector(panaction:)]; [pan setdelegate:self]; [self addgesturerecognizer:pan]; tap1=[[uitapgesturerecognizer alloc]initwithtarget:self action:@selector(tapaction:)]; [tap1 setdelegate:self]; [self addgesturerecognizer:tap1];  } return self; }    - (void)tapaction:(uitapgesturerecognizer *)gesturerecognizer {   //       lpinimgview=[[uiimageview alloc]initwithframe:cgrectmake(-15,-20, 30, 30)]; //    lpinimgview.image=[uiimage imagenamed:@"pin"]; //    // pin.frame=cgrectmake(frame1.origin.x, frame1.origin.y-15, 10, 10); //     //    rpinimgview=[[uiimageview alloc]initwithframe:cgrectmake      (self.frame.size.width-15 ,23, 30, 30)]; //    //pin1.frame=cgrectmake(frame1.origin.x+frame1.size.width, frame1.origin.y+5, 10, 10); //    rpinimgview.image=[uiimage imagenamed:@"pin1"]; //    [self addsubview:lpinimgview]; //    [self addsubview:rpinimgview]; nsarray *subviews=[self subviews]; nslog(@"subviews%@",subviews); if ([subviews count]>0) { [lpinimgview removefromsuperview]; [rpinimgview removefromsuperview]; }else { lpinimgview=[[uiimageview alloc]initwithframe:cgrectmake(-15,-20, 30, 30)]; lpinimgview.image=[uiimage imagenamed:@"pin"]; // pin.frame=cgrectmake(frame1.origin.x, frame1.origin.y-15, 10, 10);  rpinimgview=[[uiimageview alloc]initwithframe:cgrectmake(self.frame.size.width-15 ,23, 30, 30)]; //pin1.frame=cgrectmake(frame1.origin.x+frame1.size.width, frame1.origin.y+5, 10, 10); rpinimgview.image=[uiimage imagenamed:@"pin1"]; tap2=[[uitapgesturerecognizer alloc]initwithtarget:self action:@selector (rpinimagetap:)]; [rpinimgview addgesturerecognizer:tap2]; [tap2 setdelegate:self]; tap3=[[uitapgesturerecognizer alloc]initwithtarget:self action:@selector(lpinimagetap:)]; [rpinimgview addgesturerecognizer:tap3]; [tap3 setdelegate:self]; [self addsubview:lpinimgview]; [self addsubview:rpinimgview];  }   - (void)lpinimagetap:(uipangesturerecognizer *)gesturerecognizer {  } - (void)rpinimagetap:(uipangesturerecognizer *)gesturerecognizer {  } - (void)panaction:(uipangesturerecognizer *)gesturerecognizer {  cgpoint translatedpoint = [(uipangesturerecognizer*)gesturerecognizer   translationinview:self];  if ([(uipangesturerecognizer*)gesturerecognizer state] ==     uigesturerecognizerstatebegan) { firstx = [[gesturerecognizer view] center].x; firsty = [[gesturerecognizer view] center].y; }  //  translatedpoint = cgpointmake(firstx+translatedpoint.x, firsty); translatedpoint = cgpointmake(firstx+translatedpoint.x, firsty+translatedpoint.y);  [[gesturerecognizer view] setcenter:translatedpoint];  if ([(uipangesturerecognizer*)gesturerecognizer state] ==   uigesturerecognizerstateended) { cgfloat velocityx = (0.2*[(uipangesturerecognizer*)gesturerecognizer   velocityinview:self].x);   cgfloat finalx = translatedpoint.x + velocityx; cgfloat finaly = firsty;// translatedpoint.y + (.35*[(uipangesturerecognizer*)sender velocityinview:self.view].y);  if (uideviceorientationisportrait([[uidevice currentdevice] orientation])) { if (finalx < 0) { //finalx = 0; } else if (finalx > 768) { //finalx = 768; }  if (finaly < 0) { finaly = 0; } else if (finaly > 1024) { finaly = 1024; } } else { if (finalx < 0) { //finalx = 0; } else if (finalx > 1024) { //finalx = 768; }  if (finaly < 0) { finaly = 0; } else if (finaly > 768) { finaly = 1024; } } } } 

}

have @ below link , download project , check:

https://github.com/spoletto/spuserresizableview


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -