我已经查看并找到了使用按钮制作 d-pad 的代码,但您必须不断点击按钮才能使其工作。所以如果你想上去,你必须不断地向上推。如何在用户按住按钮的情况下使对象移动。这是我已经拥有的按钮的代码
-(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);
}];
}