Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 目标C:将UIView返回到另一个UIView';s的中心点重叠?_Objective C_Ios - Fatal编程技术网

Objective c 目标C:将UIView返回到另一个UIView';s的中心点重叠?

Objective c 目标C:将UIView返回到另一个UIView';s的中心点重叠?,objective-c,ios,Objective C,Ios,我在屏幕上拖动一个UIView,当UIView的中心与另一个UIView(视图Y)重叠时,我希望返回视图Y Objective-C中有没有一种方法可以做到这一点?这应该是你喜欢的。如果您使用的是UiPanGesture而不是touchsmoved,只需移动If语句即可 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [ViewA setCenter:[[touches anyObject] locati

我在屏幕上拖动一个UIView,当UIView的中心与另一个UIView(视图Y)重叠时,我希望返回视图Y


Objective-C中有没有一种方法可以做到这一点?

这应该是你喜欢的。如果您使用的是UiPanGesture而不是touchsmoved,只需移动If语句即可

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    [ViewA setCenter:[[touches anyObject] locationInView:self.view]];

    if (CGRectContainsPoint(ViewB.frame,viewA.center)){
         // Do something with ViewB
    }
}

我有几个不同的观点,这个主要观点可能会触及。这是检查哪个uiview被传递的最简单的方法吗?这是目前为止最简单的方法。这是所有碰撞检测的基础。从这里开始,事情只会变得更复杂。