Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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 如何使用UITouch移动视图中的一个图像与另一个图像相交_Objective C_Animation_Uitouch - Fatal编程技术网

Objective c 如何使用UITouch移动视图中的一个图像与另一个图像相交

Objective c 如何使用UITouch移动视图中的一个图像与另一个图像相交,objective-c,animation,uitouch,Objective C,Animation,Uitouch,我正在使用UITouch方法从左到右和从右到左移动图像视图。为此,我使用下面的补丁和它的工作良好 -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { UITouch *touch1 = [[event allTouches] anyObject]; CGPoint location = [touch1 locationInView: self.view];

我正在使用
UITouch
方法从左到右和从右到左移动图像视图。为此,我使用下面的补丁和它的工作良好

-(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];
        }
    }     
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
UITouch*touch1=[[event AllTouchs]anyObject];
CGPoint location=[touch1 locationInView:self.view];
如果([touch1 view]==\u ballimg)
{
如果(位置x=20)
{
[UIView beginAnimations:nil上下文:NULL];
[UIView setAnimationDuration:1.0];
CGRect rect=CGRectMake(位置.x,_ballimg.frame.origin.y,_ballimg.frame.size.height,_ballimg.frame.size.width);
[u ballimg setFrame:rect];
[UIView委员会];
}
}
如果([touch1 view]==\u ballimg1)
{
如果(位置x=64)
{
[UIView beginAnimations:nil上下文:NULL];
[UIView setAnimationDuration:1.0];
CGRect rect=CGRectMake(location.x,_ballimg1.frame.origin.y,_ballimg1.frame.size.height,_ballimg1.frame.size.width);
[u ballimg1 setFrame:rect];
[UIView委员会];
}
}     
}

但是现在,当两个图像相交时,我必须将相交的imageView从当前触摸的imageView向左或向右向左推。最好的方法是什么?

r u运动图像或图像视图?您的代码有什么问题?@Mr.T现在我使用交叉点来表示图像相交时,然后移动一个图像,将其x值增加10,但这些图像仍然互相穿透为什么会发生这种情况