我想拖动顶部的红色圆圈UIView
并放在底部的黑色圆圈上UIView
。当黑色圆圈上至少有50%的位置时,我想将此红色圆圈放下。但是此方法仅在黑圈的完美位置时执行。当它在黑色区域圆圈中时,请给我一些解决方案。下面是我的代码
if sourceCircleView.frame.contains(destinationCircleView.frame) {
destinationCircleView.backgroundColor = UIColor.green
sourceCircleView.isHidden = true
}
if sourceCircleView.frame.contains(destinationSquareView.frame) {
sourceCircleView.backgroundColor = UIColor.red
UIView.animate(withDuration: 2, animations: {
self.sourceCircleView.center = self.sourceCircleViewCenter
}, completion: nil)
}
你可以试试
if sourceCircleView.frame.intersects(destinationCircleView.frame) {
//
}
// 要么
let rect = sourceCircleView.frame.intersection(destinationCircleView.frame)
// here compare width of rect with destinationCircleView.frame for 50% check
if rect.width >= ( destinationCircleView.frame.width / 2 ) && rect.height >= ( destinationCircleView.frame.height / 2 ) {
// intersection more than 50%
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句