2011-04-17 24 views
0

私はこのコードを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)); 
} 

しかし、私は1つのエラーが発生しますが、無効なオペランドはバイナリ/になります。 私は次の行に、このエラーを取得する:

scale = [self distance:currentTouch1 toPoint:currentTouch2]/[self distance:touch1 toPoint:touch2]; 
+0

前にそれを移動することによって、問題を解決することができます。 – kennytm

答えて

0

あなたは.hファイルでdistance:toPoint:を宣言したことがありますか?そうでなければ、コンパイラは、関数が返す型がわからず、除算演算子では動作しないものを仮定します。 toPoint:: `

だから、ほとんどの場合、あなたはどちらかが.hファイル内の関数を宣言するか、` -distanceの宣言を示してくださいtouchesMoved:withEvent:

+0

私はそれを宣言していない、それはそれでなければならない。私がtouchesMovedの前にそれを置くとき、それはまだ働かないので。どのように私は距離を宣言するのですか?答えに先進的なありがとう! – Tim

+0

touchesMoved:withEvent:の前に配置してもまだ動作しない場合は、それは別のものでなければならず、.hファイルの宣言は行いません。しかし、エラーメッセージが変更された場合は、複数の問題があります。エラーメッセージは同じですか? – Codo

+0

エラーメッセージが変更されましたが、スケールのようにtouchesMovedの下に宣言されている他のことが明らかにされています。どこに行を置く必要がありますか? – Tim