ボタン付きの方向パッドを作成するコードを調べて見つけましたが、機能させるにはボタンを常にタップする必要があります。だから、上に行きたいのなら、常に押し上げなければなりませんでした。ユーザーがボタンを押したままオブジェクトを移動するにはどうすればよいですか。これは私がすでに持っているボタンのコードです
-(IBAction)moveLeft:(id)sender{
Robot.center = CGPointMake(Robot.center.x-10, Robot.center.y);
[UIView animateWithDuration:0.5 animations:^{
Robot.center = CGPointMake(Robot.center.x, Robot.center.y+10);
}];
}
-(IBAction)moveRight:(id)sender{
Robot.center = CGPointMake(Robot.center.x+10, Robot.center.y);
[UIView animateWithDuration:0.5 animations:^{
Robot.center = CGPointMake(Robot.center.x, Robot.center.y+10);
}];
}
-(IBAction)moveUp:(id)sender{
Robot.center = CGPointMake(Robot.center.x, Robot.center.y-10);
[UIView animateWithDuration:0.5 animations:^{
Robot.center = CGPointMake(Robot.center.x, Robot.center.y+10);
}];
}
-(IBAction)moveDown:(id)sender{
Robot.center = CGPointMake(Robot.center.x, Robot.center.y+10);
[UIView animateWithDuration:0.5 animations:^{
Robot.center = CGPointMake(Robot.center.x, Robot.center.y+10);
}];
}