我正在使用UITouch
方法从左到右和从右到左移动imageView。为此,我使用下面的补丁和它正常工作
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UITouch *touch1 = [[event allTouches] anyObject];
CGPoint location = [touch1 locationInView: self.view];
if ([touch1 view] == _ballimg)
{
if (location.x<=268 && location.x>=20)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
CGRect rect = CGRectMake(location.x, _ballimg.frame.origin.y,_ballimg.frame.size.height, _ballimg.frame.size.width);
[_ballimg setFrame:rect];
[UIView commitAnimations];
}
}
if ([touch1 view] == _ballimg1)
{
if (location.x<=312 && location.x>=64)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
CGRect rect = CGRectMake(location.x, _ballimg1.frame.origin.y,_ballimg1.frame.size.height, _ballimg1.frame.size.width);
[_ballimg1 setFrame:rect];
[UIView commitAnimations];
}
}
}
但是现在当两个图像相交时,我必须从当前触摸的图像视图中从左到右或从右到左推动相交的imageView。什么是最好的方法?