[英]Drag a UIView on the bounds of another UIView (with a rounded corner)
Basically I have a UIView
which I need to drag along the bounds of another UIView
(its superview) with a rounded corner. 基本上,我有一个UIView
,我需要沿着另一个带有圆角的UIView
(其超级视图)的边界拖动。 I have already implemented a draggable UIView
. 我已经实现了可拖动的UIView
。 I'm having trouble finding a way to restrict the movement of the draggable UIView
along the edges of its superview only. 我很难找到一种方法来限制可拖动UIView
沿其超级视图的边缘移动。
Is there a way in which I can check if the UIView.center
is on the superview's bounds? 有没有一种方法可以检查UIView.center
是否在UIView.center
视图的边界上?
Anyone have any ideas on how I can implement this? 有人对我如何实现此目标有任何想法吗? Thanks 谢谢
You can use the CGRectContainsPoint to check whether an point is inside the view frame 您可以使用CGRectContainsPoint来检查一个点是否在视图框架内
-(void) methodThatWouldBeCalledWhenTheViewISDragged {
CGPoint smallViewCenter = smallView.center;
if ( CGRectContainsPoint(containerView.bounds, smallViewCenter) ) {
// smallView is inside the ContainerView
}
else{
//smallView went outside
}
}
使用CGRectContainsPoint()
进行检测。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.