0

Basically I have a UIView which I need to drag along the bounds of another UIView (its superview) with a rounded corner. I have already implemented a draggable UIView. I'm having trouble finding a way to restrict the movement of the draggable UIView along the edges of its superview only.

Is there a way in which I can check if the UIView.center is on the superview's bounds?

Anyone have any ideas on how I can implement this? Thanks

Nikunj
  • 655
  • 3
  • 13
  • 25
James
  • 291
  • 1
  • 3
  • 13

2 Answers2

1

You can use the CGRectContainsPoint to check whether an point is inside the view frame

-(void) methodThatWouldBeCalledWhenTheViewISDragged {

  CGPoint smallViewCenter = smallView.center;
    if ( CGRectContainsPoint(containerView.bounds, smallViewCenter) ) {
       // smallView is inside the ContainerView
    }
    else{   
       //smallView went outside
    }
  }
ipraba
  • 16,485
  • 4
  • 59
  • 58
  • I only want the smallView to be draggable on the outside edge of the containerView. I don't want it to be able to be dragged inside. – James Nov 17 '15 at 06:27
0

UseCGRectContainsPoint() to detect.

duan
  • 8,515
  • 3
  • 48
  • 70