传递给不带参数的调用的参数

时间:2017-01-10 23:34:30

标签: ios swift xcode

我将动画圈添加到uiview中。在这行代码中:

  var circleView = addCircleView(frame: CGRectMake(diceRoll, 0, circleWidth, circleHeight))

我收到的错误是“传递给不带参数的调用的参数”指向CGRectMake。 我有通道附加其余的代码,因为它是必要的

import UIKit
import CoreMotion
import CoreGraphics

class Animation: UIView {
var circleLayer: CAShapeLayer!

override init(frame: CGRect) {
    super.init(frame: frame)
    self.backgroundColor = UIColor.clear

    // Use UIBezierPath as an easy way to create the CGPath for the layer.
    // The path should be the entire circle.
    let circlePath = UIBezierPath(arcCenter: CGPoint(x: frame.size.width / 2.0, y: frame.size.height / 2.0), radius: (frame.size.width - 10)/2, startAngle: 0.0, endAngle: CGFloat(M_PI * 2.0), clockwise: true)

    // Setup the CAShapeLayer with the path, colors, and line width
    circleLayer = CAShapeLayer()
    circleLayer.path = circlePath.cgPath
    circleLayer.fillColor = UIColor.clear.cgColor
    circleLayer.strokeColor = UIColor.red.cgColor
    circleLayer.lineWidth = 5.0;

    // Don't draw the circle initially
    circleLayer.strokeEnd = 0.0

    // Add the circleLayer to the view's layer's sublayers
    layer.addSublayer(circleLayer)
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}
func animateCircle(duration: TimeInterval) {
    // We want to animate the strokeEnd property of the circleLayer
    let animation = CABasicAnimation(keyPath: "strokeEnd")

    // Set the animation duration appropriately
    animation.duration = duration

    // Animate from 0 (no circle) to 1 (full circle)
    animation.fromValue = 0
    animation.toValue = 1

    // Do a linear animation (i.e. the speed of the animation stays the same)
    animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)

    // Set the circleLayer's strokeEnd property to 1.0 now so that it's the
    // right value when the animation ends.
    circleLayer.strokeEnd = 1.0

    // Do the actual animation
    circleLayer.add(animation, forKey: "animateCircle")
}
func addCircleView() {
    let diceRoll = CGFloat(Int(arc4random_uniform(7))*50)
    var circleWidth = CGFloat(200)
    var circleHeight = circleWidth

    // Create a new CircleView
    var circleView = addCircleView(frame: CGRectMake(diceRoll, 0, circleWidth, circleHeight))

    UIView.addSubview(circleView)

    // Animate the drawing of the circle over the course of 1 second
    circleView.animateCircle(1.0)
}

}

致Mike S的信用

1 个答案:

答案 0 :(得分:1)

虽然我将CGRectMake的所有引用更改为CGRect,但问题是调用addCircle()。你没有定义任何参数。

尝试将事情改为:

func addCircleView(frame: CGRect) {

或者,由于addCircleView看起来不使用此参数,请尝试从调用addCircle()中删除CGRect / CGRectMake:

var circleView = addCircleView()

(看起来你可能想要前者。)