Trying to add collision detection without spritekit with UICollisionBehavior

Racking my head on how to finish collision.addItem as! (UIDynamicItem) I am getting the warning that UIDynamicItem is not being used. and the error: Could not cast value of type 'Swift._EmptyArrayStorage' (0x10d8959b0) to '__ObjC.UIDynamicItem' (0x600000264518). I am still using swift 3.

  func dropBall() {
    //Create a ball
    let circlePath = UIBezierPath(arcCenter: CGPoint(x: 20,y: 20), radius: CGFloat(20), startAngle: CGFloat(0), endAngle:CGFloat(Double.pi * 2), clockwise: true)

    let shapeLayer = CAShapeLayer()
    shapeLayer.path = circlePath.cgPath

    //change the fill color
    shapeLayer.fillColor = UIColor.clear.cgColor
    //you can change the stroke color
    shapeLayer.strokeColor = UIColor.red.cgColor
    //you can change the line width
    shapeLayer.lineWidth = 3.0
    let circleView = UIView(frame: CGRect(x: frame.width / 2, y: 0, width: 50, height: 50))
    addSubview(circleView)

    circleView.layer.addSublayer(shapeLayer)

    animator = UIDynamicAnimator(referenceView: self)
    gravity = UIGravityBehavior(items: [circleView])
    //Gives direction to bottom of screen
    let direction = CGVector(dx: 0.0, dy: 1.0)
    gravity.gravityDirection = direction

    //Add Collision Detection 
    let boundries = UICollisionBehavior(items: [circleView])
    boundries.translatesReferenceBoundsIntoBoundary = true



    //Add Collision Detection with Cicle and Lines
    let collision = UICollisionBehavior(items: [circleView, finishedLines as! UIDynamicItem])
    collision.addItem as! (UIDynamicItem)



    animator?.addBehavior(collision)
    animator?.addBehavior(boundries)
    animator?.addBehavior(gravity)

}
链接地址: http://www.djcxy.com/p/96798.html

上一篇: Access不允许使用Origin

下一篇: 尝试使用UICollisionBehavior添加没有spritekit的冲突检测