0

私のクラス (UIView) は、Xcode 8.1 の迅速な 3 変換後に動作しません。ここで何が問題なのかわかりません。このクラスは、変換後に正常に見える進行状況ビューですが、進行状況が表示されません。変換後の私のクラスは次のとおりです。

class CircularLoaderView: UIView, CAAnimationDelegate {
    let circlePathLayer = CAShapeLayer()
    let circleRadius: CGFloat = 60.0
    let innerCirclePathLayer = CAShapeLayer()
    let innerCircleRadius: CGFloat = 60.0
    override init(frame: CGRect) {
        super.init(frame: frame)
        configure()
        innerConfigure()
    }
    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)!
        configure()
        innerConfigure()
    }
    func configure() {
        circlePathLayer.frame = bounds
        circlePathLayer.lineWidth = 10
        circlePathLayer.fillColor = UIColor.clear.cgColor
        circlePathLayer.strokeColor = UIColor.darkGray.cgColor
        layer.addSublayer(circlePathLayer)
        backgroundColor = UIColor.clear
        progress = 0
    }
    func innerConfigure() {
        innerCirclePathLayer.frame = bounds
        innerCirclePathLayer.lineWidth = 10
        innerCirclePathLayer.fillColor = UIColor.clear.cgColor
        innerCirclePathLayer.strokeColor = UIColor(red: 100, green: 60, blue: 70, alpha: 0.2).cgColor
        layer.addSublayer(innerCirclePathLayer)
        backgroundColor = UIColor.clear
    }
    func innerCircleFrame() -> CGRect {
        var circleFrame = CGRect(x: 0, y: 0, width: 2*innerCircleRadius, height: 2*innerCircleRadius)
        circleFrame.origin.x = innerCirclePathLayer.bounds.midX - circleFrame.midX
        circleFrame.origin.y = innerCirclePathLayer.bounds.midY - circleFrame.midY
        return circleFrame
    }
    func innerCirclePath() -> UIBezierPath {
        return UIBezierPath(ovalIn: innerCircleFrame())
    }
    func circleFrame() -> CGRect {
        var circleFrame = CGRect(x: 0, y: 0, width: 2*circleRadius, height: 2*circleRadius)
        circleFrame.origin.x = circlePathLayer.bounds.midX - circleFrame.midX
        circleFrame.origin.y = circlePathLayer.bounds.midY - circleFrame.midY
        return circleFrame
    }
    func circlePath() -> UIBezierPath {
        return UIBezierPath(ovalIn: circleFrame())
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        circlePathLayer.frame = bounds
        circlePathLayer.path = circlePath().cgPath
        innerCirclePathLayer.frame = bounds
        innerCirclePathLayer.path = innerCirclePath().cgPath
    }
    var progress: CGFloat {
        get {
            return circlePathLayer.strokeEnd
        }
        set {
            if (newValue > 1) {
                circlePathLayer.strokeEnd = 1
            } else if (newValue < 0) {
                circlePathLayer.strokeEnd = 0
            } else {
                circlePathLayer.strokeEnd = newValue
            }
        }
    }
    func reveal() {
        // 1
        backgroundColor = UIColor.clear
        progress = 1
        // 2
        circlePathLayer.removeAnimation(forKey: "strokeEnd")
        // 3
        circlePathLayer.removeFromSuperlayer()
        superview?.layer.mask = circlePathLayer

        // 1
        let center = CGPoint(x: bounds.midX, y: bounds.midY)
        let finalRadius = sqrt((center.x*center.x) + (center.y*center.y))
        let radiusInset = finalRadius - circleRadius
        let outerRect = circleFrame().insetBy(dx: -radiusInset, dy: -radiusInset)
        let toPath = UIBezierPath(ovalIn: outerRect).cgPath
        // 2
        let fromPath = circlePathLayer.path
        let fromLineWidth = circlePathLayer.lineWidth
        // 3
        CATransaction.begin()
        CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions)
        circlePathLayer.lineWidth = 2*finalRadius
        circlePathLayer.path = toPath
        CATransaction.commit()
        // 4
        let lineWidthAnimation = CABasicAnimation(keyPath: "lineWidth")
        lineWidthAnimation.fromValue = fromLineWidth
        lineWidthAnimation.toValue = 2*finalRadius
        let pathAnimation = CABasicAnimation(keyPath: "path")
        pathAnimation.fromValue = fromPath
        pathAnimation.toValue = toPath
        // 5
        let groupAnimation = CAAnimationGroup()
        groupAnimation.duration = 1
        groupAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
        groupAnimation.animations = [pathAnimation, lineWidthAnimation]
        groupAnimation.delegate = self
        circlePathLayer.add(groupAnimation, forKey: "strokeWidth")
    }
     func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
        superview?.layer.mask = nil
    }
}

これは私が進行状況を設定する方法です:

cell.loaderView?.progress = CGFloat(receivedSize)/CGFloat(expectedSize)

まだ進行状況が表示されていません。誰かがここで何が問題なのか手がかりを持っているので、私に知らせてください

4

1 に答える 1

1

何が機能していないかを正確に指定していませんが、コードをテストすると進行状況が表示されますが、色を分割していないため表示されていないだけでしinnerCirclePathLayerた。として。そこで一旦 RGB を に分割してみてください。RGB255init(red:green:blue:alpha:)0.01.01.01.0255

innerCirclePathLayer.strokeColor = UIColor(red: 100/255.0, green: 60/255.0, blue: 70/255.0, alpha: 0.2).cgColor
于 2016-11-19T05:48:29.370 に答える