How to resize UIView using corner handles - similar to Pages, Keynote,

I need to add descriptors (in corners) so that the user can resize this view. Something like editing graphics in Apple Pages or Key apps. (or in any other graphical application). I tried to add subviews handlers to a specific view, but those views only got touches where both overlap, within the given view boundaries. I need to be able to drag any of the corners that will change the frame or borders of this view. (this part I'm already working on).

Any suggestions, guides, links would be appreciated :)

I am new, so I can’t :( send images, so look at the link

+4
source share
2 answers

I would make a UIGripView that inherits from the UIView, which is above the view you want.

It would be:

  • Get an idea of ​​how to manipulate and size accordingly (slightly larger, but with the same center)
  • Draw it yourself (captures and borders) - implement -(void) drawRect:(CGRect)rect
  • Register gesture recognizers
  • When the clutch moves, resize the main view and yourself accordingly.
  • When the center moves, move the center of the main view and yourself.

It may be easier for you to handle gestures if you do every grip with a UIView, but it’s not difficult to make some zones in your view and check which one is located.

(Remember to make the sensory zones large enough)

+2
source
  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch = [[event allTouches] anyObject]; touchStart = [[touches anyObject] locationInView:self]; isResizingLR = (self.bounds.size.width - touchStart.x < kResizeThumbSize && self.bounds.size.height - touchStart.y < kResizeThumbSize); isResizingUL = (touchStart.x <kResizeThumbSize && touchStart.y <kResizeThumbSize); isResizingUR = (self.bounds.size.width-touchStart.x < kResizeThumbSize && touchStart.y<kResizeThumbSize); isResizingLL = (touchStart.x <kResizeThumbSize && self.bounds.size.height -touchStart.y <kResizeThumbSize); } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ CGPoint touchPoint = [[touches anyObject] locationInView:self]; CGPoint previous=[[touches anyObject]previousLocationInView:self]; float deltaWidth = touchPoint.x-previous.x; float deltaHeight = touchPoint.y-previous.y; if (isResizingLR) { self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y,touchPoint.x + deltaWidth, touchPoint.y + deltaWidth); } if (isResizingUL) { self.frame = CGRectMake(self.frame.origin.x + deltaWidth, self.frame.origin.y + deltaHeight, self.frame.size.width - deltaWidth, self.frame.size.height - deltaHeight); } if (isResizingUR) { self.frame = CGRectMake(self.frame.origin.x ,self.frame.origin.y + deltaHeight, self.frame.size.width + deltaWidth, self.frame.size.height - deltaHeight); } if (isResizingLL) { self.frame = CGRectMake(self.frame.origin.x + deltaWidth ,self.frame.origin.y , self.frame.size.width - deltaWidth, self.frame.size.height + deltaHeight); } if (!isResizingUL && !isResizingLR && !isResizingUR && !isResizingLL) { self.center = CGPointMake(self.center.x + touchPoint.x - touchStart.x,self.center.y + touchPoint.y - touchStart.y); } } 
+1
source

All Articles