Objective c 错误:“二进制/的操作数无效”

Objective c 错误:“二进制/的操作数无效”,objective-c,cocoa-touch,ios,division,Objective C,Cocoa Touch,Ios,Division,我使用这段代码来移动、缩放和旋转UIImageView - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint currentTouch1; CGPoint currentTouch2; NSArray *allTouches = [touches allObjects]; UITouch* t; float scale,rotation; if([[

我使用这段代码来移动、缩放和旋转UIImageView

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    CGPoint currentTouch1;
    CGPoint currentTouch2;
    NSArray *allTouches = [touches allObjects];
    UITouch* t;
    float scale,rotation;

    if([[event allTouches] count]==1){
        t=[[[event allTouches] allObjects] objectAtIndex:0];
        if (CGRectContainsPoint([Birdie frame], [[allTouches objectAtIndex:0] locationInView:self.view]))
        { 
            touch2=[t locationInView:nil];
            Birdie.center=CGPointMake(Birdie.center.x+touch2.x-touch1.x,Birdie.center.y+touch2.y-touch1.y);
            touch1=touch2;
        }
    }
    else if([[event allTouches] count]==2)
    {
        t=[[[event allTouches] allObjects] objectAtIndex:0];
        currentTouch1=[t locationInView:nil];

        t=[[[event allTouches] allObjects] objectAtIndex:1];
        currentTouch2=[t locationInView:nil];


        scale = [self distance:currentTouch1 toPoint:currentTouch2] / [self distance:touch1 toPoint:touch2];
        rotation=atan2(currentTouch2.y-currentTouch1.y, currentTouch2.x-currentTouch1.x)-atan2(touch2.y-touch1.y,touch2.x-touch1.x);
        if(isnan(scale)){
            scale=1.0f;
        }
        NSLog(@"rotation %f",rotation);

        NSLog(@"scale %f",scale);

        if (CGRectContainsPoint([Birdie frame], [[allTouches objectAtIndex:0] locationInView:self.view]) &&
            CGRectContainsPoint([Birdie frame], [[allTouches objectAtIndex:1] locationInView:self.view]))
        {

            Birdie.transform=CGAffineTransformScale(Birdie.transform, scale,scale);
            Birdie.transform=CGAffineTransformRotate(Birdie.transform, rotation);
        }
        else // In case of scaling or rotating the background imageView
        {
            imageView.transform=CGAffineTransformScale(imageView.transform, scale,scale);
            imageView.transform=CGAffineTransformRotate(imageView.transform, rotation);
        }

        touch1=currentTouch1;
        touch2=currentTouch2;
    }
}

-(double)distance:(CGPoint)point1 toPoint:(CGPoint)point2
{
    return sqrt(fabs(point1.x - point2.x) + fabs(point1.y - point2.y));
}
但是,我一直都有一个错误,即二进制/的操作数无效。 我在下一行得到了这个错误:

    scale = [self distance:currentTouch1 toPoint:currentTouch2] / [self distance:touch1 toPoint:touch2];
您是否在.h文件中声明了distance:toPoint:?如果不是,那么编译器只需一次传递就可以从上到下严格地工作,它不知道函数返回的是什么类型,并且假定除法运算符不起作用


因此,最有可能的解决方法是在.h文件中声明函数,或者在触摸Moved:withEvent:

之前移动它。我还没有声明它,它一定是这样。因为当我在触摸之前把它放进去的时候,它仍然不起作用。如何声明距离:topoint than?谢谢你的回答!如果您在touchMoved:withEvent:之前输入,但它仍然不起作用,那么它肯定是其他东西,并且.h文件中的声明也不会起作用。但是,如果错误消息已更改,则您有多个问题。错误消息是否仍然相同?错误消息已更改,但还有其他未声明的内容,这些内容在touchesMoved下面声明,如scale。我必须准确地把这行放在哪里?但是如果我把它放在前面,我会得到错误消息“self”未声明。那么这难道不是别的吗?请显示-distance:toPoint:的声明。