尝试使用UICollisionBehavior添加没有spritekit的冲突检测

把我的头放在如何完成collision.addItem上! (UIDynamicItem)我收到UIDynamicItem未被使用的警告。 和错误:无法将类型'Swift._EmptyArrayStorage'(0x10d8959b0)的值转换为'__ObjC.UIDynamicItem'(0x600000264518)。 我仍然在快速使用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/96797.html

上一篇: Trying to add collision detection without spritekit with UICollisionBehavior

下一篇: UICollisionBehavior collide with background view only