UiScrollview平移缓慢

时间:2018-01-23 15:09:50

标签: ios uiscrollview uiimageview calayer

我的uiscrollview包含名为m的图像视图;我在m上添加了大约100个子视图没有问题,但是当我绘制每个子视图的路径和形状图层时,平移变得非常慢。

为什么?有替代方案还是解决方案?

编辑:代码的一部分,m是scrollview内部的imageview,对象是subview,我调用此函数来绘制约200个子视图的路径

for objectData in self.objectDatas
    {

        let object = UIImageView(frame: CGRect(x:line.point1X, y:line.point1Y, width: 200, height: 200))
        object.tag = objectData.ID
        object.isUserInteractionEnabled = true
        object.backgroundColor = UIColor.blue

        let mask = CAShapeLayer()
        mask.frame = object.layer.bounds
        path.move(to: CGPoint(x: x1-diff, y: y1+diff))

        let path = CGMutablePath()

        let diff = 5
        let x1 = 0 // regarding the object, not 'm' object
        let y1 = 0 // regarding the object, not 'm' object
        let x2 = objectData.point2X - objectData.point1X
        let y2 = objectData.point2Y - objectData.point1Y

        path.addLine(to: CGPoint(x: x2-diff, y: y2+diff))
        path.addArc(center: CGPoint(x: x2, y: y2), radius:CGFloat(diff) , startAngle: -.pi, endAngle: 0, clockwise: true)
        path.addLine(to: CGPoint(x: x1+diff, y: y1-diff))
        path.addArc(center: CGPoint(x: x1, y: y1), radius:CGFloat(diff) , startAngle: 0, endAngle: -.pi, clockwise: true)
        path.addLine(to: CGPoint(x: x1-diff, y: y1+diff))
        mask.path = path

        object.layer.mask = mask

        let shape = CAShapeLayer()
        shape.frame = object.bounds
        shape.path = path
        shape.lineWidth = 5
        shape.strokeColor = UIColor.black.cgColor
        shape.fillColor = UIColor.red.cgColor
        shape.borderColor = UIColor.green.cgColor
        object.layer.insertSublayer(shape, at: 0)

        let tgr = UITapGestureRecognizer(target: self, action: #selector("action"))
        tgr.delegate = self
        object.addGestureRecognizer(tgr)

        self.m.addObject(object: object)
    }

0 个答案:

没有答案