【问题标题】:Select part of GLKViewController选择部分 GLKViewController
【发布时间】:2016-02-08 15:40:13
【问题描述】:

我正在尝试在我的项目中实现this。但我有一些麻烦。我打算使用 UiPanGestureRecognizer 来改变矩形的大小。据我了解,我应该使用 UIVIew 和自定义 drawRect 方法?

【问题讨论】:

    标签: ios swift uiview selection drawrect


    【解决方案1】:

    为您的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 是 get-only 属性
    • @OkadzakiTomoe 已修复,应该是 frame.size.widthcustomView 是您正在调整大小的视图,currentFrame 只是一个属性,您应该在手势结束后将 customView 的框架保存到,以便调整大小正常工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 2011-09-11
    • 2012-10-26
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多