1

画面下部に画像があります。

次のように、特定のYポイントに到達するまで画像を上に移動してもらいたいです。

[door setCenter:CGPointMake(160,347)];

これまでのところ、画像(ドア)を上にドラッグすると、目的のポイントを超えて続行されますが、離すと、正しい位置にスナップバックします。

ユーザーの指がまだ上にスワイプしている場合、特定のポイントに達したときに画像の移動を停止するにはどうすればよいですか?それはifステートメントの中にありますか?

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if (startPoint.y < 347) {
         // something in here ?????
    }
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *myTouch = [touches anyObject];
    startPoint = [myTouch locationInView:self.view];
    NSLog(@"position = %f and  %f",startPoint.x,startPoint.y);
    [door setCenter:CGPointMake(160, startPoint.y)];
}  

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    [door setCenter:CGPointMake(160,347)];
}
4

1 に答える 1

1

touchesMovedメソッドで設定してみてはいかがでしょうか。何かのようなもの、

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *myTouch = [touches anyObject];
    startPoint = [myTouch locationInView:self.view];
    NSLog(@"position = %f and  %f",startPoint.x,startPoint.y);
    if (startPoint.y < 347) { //or suitable condition to verify your case
        [door setCenter:CGPointMake(160, startPoint.y)]; //then only set the center
    } else 
    { 
       [door setCenter:CGPointMake(160,347); 
    } 
}  
于 2012-10-28T18:55:31.707 に答える