选择GLKViewController的一部分
问题描述:
我试着在我的项目中实现this。但我有一些麻烦。我打算使用UiPanGestureRecognizer来改变矩形的大小。据我所知,我应该使用UIVIew和自定义drawRect方法?选择GLKViewController的一部分
答
添加操作为您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
。
我不明白。什么是currentFrame? –
而且,customView.frame.width是只能得到的属性 –
@OkadzakiTomoe固定,它应该是'frame.size.width'。 'customView'是你调整大小的视图,'currentFrame'只是一个属性,你应该在手势结束后保存'customView'的框架,这样调整大小才能正常工作。 – xoudini