我无法给我的视角提供新的角半径

时间:2018-02-28 09:48:31

标签: swift

我在视图中创建了一些圈子,如果我在靠近下一个圈子的某个地方调整大小时我想调整它们的大小,当我在sender.state == .ended上用手势调整它们时,它们会调整大小但是它不会改变我希望调整大小的角半径。

let circle = UIView(frame: CGRect(x: 0.0, y: 0.0, width: a, height: a))

        circle.center = self.view.center
        circle.layer.cornerRadius = CGFloat(cornerRad)
        circle.backgroundColor = UIColor.black.withAlphaComponent(0.0)
        circle.layer.borderWidth = CGFloat(b)
        circle.layer.borderColor = UIColor.red.cgColor

        circle.clipsToBounds = true

        let pinchCircle = UIPinchGestureRecognizer(target: self, action: #selector(changeSize))
        //let longPressCircle = UILongPressGestureRecognizer(target: self, action: #selector(erraseCircle))
        circle.addGestureRecognizer(pinchCircle)
        //circle.addGestureRecognizer(longPressCircle)

        self.view.addSubview(circle)
        arrayShapes.append(circle)
if let view = sender.view {
        view.transform = CGAffineTransform(scaleX: sender.scale, y: sender.scale)

        let maxScale: CGFloat = 300 //Anything
        let minScale: CGFloat = 0.5 //Anything
        let scale = view.frame.size.width
        if scale > maxScale {
            view.transform = CGAffineTransform(scaleX: maxScale / scale, y: maxScale / scale)
            arrFin[pos] = Double(view.frame.size.width)
        }
        else if scale < minScale {
            view.transform = CGAffineTransform(scaleX: minScale / scale, y: minScale / scale)
            arrFin[pos] = Double(view.frame.size.width)
        } else {
            arrFin[pos] = Double(view.frame.size.width)
        }
        for (i, _) in arrayShapes.enumerated() {
            if arrayShapes[i].frame.width < view.frame.size.width{
                self.view.sendSubview(toBack: view)
            }
        }

        if sender.state == .ended {
            for (z, _) in arrFin.enumerated() where z != pos{
                let sum = arrFin[pos] - arrFin[z]
                let res = arrFin[z] - arrFin[pos]
                if arrFin[pos] == arrFin[z] || sum <= 20 || res >= 20{
                    arrFin[pos] = arrPos[pos]
                    sender.view?.layer.masksToBounds = true
                    sender.view?.layer.cornerRadius = CGFloat(arrPos[pos]) / 2
                    sender.view?.frame.size.width = CGFloat(arrPos[pos])
                    sender.view?.frame.size.height = CGFloat(arrPos[pos])
                    sender.view?.center = self.view.center
                    print(arrPos[pos])
                    break
                }
            }
        }

1 个答案:

答案 0 :(得分:0)

解决方案是在for循环上使用sender.view?.transform = CGAffineTransform.identity,而不是试图强制大小。 问题是,我试图调整到以前的值,但我的缩放比较混乱了这些数字。