【发布时间】:2016-02-08 15:40:13
【问题描述】:
我正在尝试在我的项目中实现this。但我有一些麻烦。我打算使用 UiPanGestureRecognizer 来改变矩形的大小。据我了解,我应该使用 UIVIew 和自定义 drawRect 方法?
【问题讨论】:
标签: ios swift uiview selection drawrect
我正在尝试在我的项目中实现this。但我有一些麻烦。我打算使用 UiPanGestureRecognizer 来改变矩形的大小。据我了解,我应该使用 UIVIew 和自定义 drawRect 方法?
【问题讨论】:
标签: ios swift uiview selection drawrect
为您的UIPanGestureRecognizer 添加一个操作并使用translation:
func wasDragged(gesture: UIPanGestureRecognizer) {
let translation = gesture.translationInView(self.view)
// Do your resizing here, e.g. from a
customView.frame.size.width = currentFrame.width + translation.x
customView.frame.size.height = currentFrame.height + translation.y
if gesture.state == .Ended {
currentFrame = customView.frame
}
}
使用此方法,添加一个CGRect 变量来存储currentFrame。
【讨论】:
frame.size.width。 customView 是您正在调整大小的视图,currentFrame 只是一个属性,您应该在手势结束后将 customView 的框架保存到,以便调整大小正常工作。