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

问题描述 投票:0回答:1

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

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
                }
            }
        }
swift
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.