0

画像が特定の領域を横切ったかどうかを確認するコーディングを行いましたが、

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

CGPoint loc=[touch locationInView:self.view];

if (touch.view==img2Obj) {
    NSLog(@"image2");
    img2Obj.center=loc;

    currentx1=img2Obj.frame.origin.x;
    currenty1=img2Obj.frame.origin.y;
    //NSLog(@"top left corner x and y is %.1f and %.1f",img2Obj.frame.origin.x,img2Obj.frame.origin.y);
    [self isImg1InPos];

}}
-(void)isImg1InPos {

int dx,dy;

dx=currentx1-x1;
dy=currenty1-y1;
if (abs(dx)<5 && abs(dx)<5) {
    NSLog(@"Image must stop moving after this!!!");
    [img2Obj setUserInteractionEnabled:FALSE];
}
//NSLog(@"unsigned int is %d",abs(dx));

}

条件を通過したら画像の動きを止めたい。

[img2Obj setUserInteractionEnabled:FALSE];

しかし、うまくいきません。この問題を解決する方法を誰か教えてください

よろしくお願いします

4

1 に答える 1

1

BOOLeg という名前の別の値を保持し、このフラグの値に基づいてルーチンmovingEnabledを早期に (つまり、画像の位置を調整する前に) 終了します。touchesMoved

于 2012-10-29T11:21:43.683 に答える