Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript,iPhone:按住按钮时重复操作_Javascript_Iphone - Fatal编程技术网

JavaScript,iPhone:按住按钮时重复操作

JavaScript,iPhone:按住按钮时重复操作,javascript,iphone,Javascript,Iphone,我在一个网站上工作,我想在iPhone上工作,但是我想要它,这样他们可以点击并按住按钮,让它继续启动onclick事件。我让它在其他浏览器中工作,但iPhone是唯一需要按下按钮的浏览器。按下按钮时是否有重复功能的方法?谢谢。根据按钮发送的触地和触地内部消息启动和停止计时器。假定按钮设置为将其触地和触地内方法链接到以下方法。您也可以在触地时设置标志“BOOL firing=TRUE;”并在触地时取消设置。您的游戏循环可以查看该标志并做出决定 @interface TouchTest : UIVi

我在一个网站上工作,我想在iPhone上工作,但是我想要它,这样他们可以点击并按住按钮,让它继续启动onclick事件。我让它在其他浏览器中工作,但iPhone是唯一需要按下按钮的浏览器。按下按钮时是否有重复功能的方法?谢谢。

根据按钮发送的触地和触地内部消息启动和停止计时器。假定按钮设置为将其触地和触地内方法链接到以下方法。您也可以在触地时设置标志“BOOL firing=TRUE;”并在触地时取消设置。您的游戏循环可以查看该标志并做出决定

@interface TouchTest : UIViewController {
NSTimer *touchDownTimer;
}

@property (nonatomic,retain)  NSTimer   *touchDownTimer;

- (IBAction) touchDown: (id) sender;
- (IBAction) touchUp: (id) sender;

@end

@implementation TouchTest
@synthesize touchDownTimer;

- (void)viewDidLoad {
 [super viewDidLoad];

 UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
 button.frame = CGRectMake(100.00, 100.00, 105.0, 37.0);
 [button setTitle:@"Fire at Will" forState:UIControlStateNormal];
 [button addTarget:(id)self action:@selector(touchDown:) forControlEvents:UIControlEventTouchDown];
 [button addTarget:(id)self action:@selector(touchUp:) forControlEvents:UIControlEventTouchUpInside];

 [self.view addSubview:button];
 }

- (IBAction) fireWeapon {
    NSLog(@"WeaponFired");
}

- (IBAction) touchDown :(id) sender{
    touchDownTimer = [NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval).3 target:self selector:@selector(fireWeapon) userInfo:nil repeats:TRUE];
}

- (IBAction) touchUp :(id) sender {
    [touchDownTimer invalidate];
}
@end

我喜欢你的太空入侵者游戏!事实上,这正是为什么,我需要能够在按住iPhone上的按钮时进行拍摄。如果触地是在按钮内部,而触地是在外部呢?