gpt4 book ai didi

JavaScript,iPhone : Repeat Action while Holding Button

转载 作者:行者123 更新时间:2023-11-28 10:32:17 31 4
gpt4 key购买 nike

我正在开发一个网站,我想在 iPhone 上工作,但是我希望他们可以点击并按住按钮并让它继续触发 onclick 事件。我让它在其他浏览器中工作,但 iPhone 是唯一需要按住按钮的浏览器。有没有办法在按住按钮时重复执行某个功能?谢谢。

最佳答案

根据按钮发送的 touchDown 和 touchUpInside 消息启动和停止计时器。假设将 Button 设置为将其 touchDown 和 touchUpInside 方法链接到以下方法。您也可以设置一个标志“BOOLfire = 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

关于JavaScript,iPhone : Repeat Action while Holding Button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2703379/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com