如何通过触摸 uiview 的角来调整 uiview 的大小。例如触摸左上角并向上拖动它的 y 坐标和高度应该增加,如果拖动右下角,那么它的原点应该相同,但高度和宽度应该改变。
最佳答案
您可以通过更改 view.layer anchor 来实现。
您可以在这里阅读: Layer Geometry
要获取可以使用的 UIView 角 -
CGRect topLeftCorner = CGRectMake(CGRectGetMinX(self.view),CGRectGetMinY(self.view),20,20); //Will define the top-left corner of the view with 20 pixels inset. you can change the size as you wish.
CGRect topRightCorner = CGRectMake(CGRectGetMaxX(self.view),CGRectGetMinY(self.view),20,20); //Will define the top-right corner.
CGRect bottomRightCorner = CGRectMake(CGRectGetMinX(self.view),CGRectGetMaxY(self.view),20,20); //Will define the bottom-right corner.
CGRect bottomLeftCorner = CGRectMake(CGRectGetMinX(self.view),CGRectGetMinY(self.view),20,20); //Will define the bottom-left corner.
然后,如果触摸点位于其中一个角的内部,您就可以检查。并根据其设置layer.anchorPoint。
BOOL isBottomLeft = CGRectContainsPoint(bottomLeftCorner, point);
if(isLeft) view.layer.anchorPoint = CGPoint(0,0);
//And so on for the others (off course you can optimize this code but I wanted to make the explanation simple).
然后,当您调整 View 大小时,它将从 anchor 调整大小。
祝你好运
关于objective-c - 从角落调整 uiview 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8710077/