touchesMoved メソッドを使用して、画像が画面の下部に沿って誰かの指を「たどる」ようにしています。したがって、画像は指の x 位置に従いますが、y 位置は無視され、下部で垂直方向に固定されたままになります (水平方向には固定されません)。これを実装する方法はありますか?
これは私のコードです:
- (void)viewDidLoad
{
[super viewDidLoad];
// create basket image that will be shown on the screen
basketView = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"bucket.png"]];
basketView.frame = CGRectMake(130.0, 412.0, 50.0, 50.0);
[self.view addSubview:basketView];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// get current touch location
UITouch *touch = [[event touchesForView:self.view] anyObject];
CGPoint point = [touch locationInView:self.view];
// update location of the image
basketView.center = point;
}