objective-c - 从角落调整 uiview 的大小

标签 objective-c ios cocoa-touch uiview touches

如何通过触摸 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/

相关文章:

iOS - 将 subview 添加到 subview Controller View

iphone - 如何检测类的属性何时更改

objective-c - (char **)(&samples) 声明了什么?

ios - UIControlEventTouchDragExit 在距 UIButton 100 像素时触发

iOS 在 UIWebBrowserView 上以编程方式禁用 Quicktype 键盘

ios - 在 UITabBar 项下添加 gif 动画

ios - 即使设备处于横向,也可以纵向启动应用程序

objective-c - 属性不能标记为@objc,因为它的类型不能在 Objective-C 中表示

ios - 在另一个 swift 类中使用 String

iphone - 类 'Foo' 的重复接口(interface)声明