HomeiOS Developmentios - UICollisionBehavior not detecting when utilizing collision with UIView.animate

ios – UICollisionBehavior not detecting when utilizing collision with UIView.animate


I’ve correctly arrange UIDynamicBehavior and UICollisionBehavior nonetheless, none of my collisions are getting acknowledged as successful within the delegate. I do not need to use UIGravityBehavior to deal with my “falling” animations so I used UIView.animate as a substitute however not one of the delegate strategies are getting hit.

class Check: UIViewController {
  let collision = UICollisionBehavior()
  let animator: UIDynamicAnimator?

  override func viewDidLoad() {
        /// view logic right here
        animator = UIDynamicAnimator(referenceView: view)
        animator?.addBehavior(boundaryCollisionBehavior)
        boundaryCollisionBehavior.collisionDelegate = self
        boundaryCollisionBehavior.collisionMode = .boundaries
        setupViews()
  }

   override func viewDidAppear(_ animated: Bool) {
        tremendous.viewDidAppear(animated)
        boundaryCollisionBehavior.addBoundary(
            withIdentifier: "shelf" as NSCopying,
            from: CGPoint(x: 0, y: 200),
            to: CGPoint(x: self.view.body.width, y: 200)
        )
    }

   func setupViews() {
        let viewsForCollision: [UIView] = [view1, view2, view3]
                UIView.animate(withDuration: animationTime, delay: 0, choices: [.curveLinear], animations: {
            viewsForCollision.forEach { $0?.remodel = .identification }
        })

       viewsForCollision.compactMap { $0 }.forEach(boundaryCollisionBehavior.addItem)
   }
}

extension Check: UICollisionBehaviorDelegate {
    func collisionBehavior(
        _ conduct: UICollisionBehavior,
        endedContactFor merchandise: UIDynamicItem,
        withBoundaryIdentifier identifier: NSCopying?
    ) {
        guard let boundary = identifier as? String else {
            return
        }

        if boundary == "shelf" {
            // Do one thing
        }
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments