2010-04-24 2 views
1

iPhone에서 작업하고 싶은 웹 사이트에서 작업하고 있습니다. 그러나 버튼을 누른 상태로 유지하면서 계속 onclick 이벤트를 실행할 수 있도록하고 싶습니다. 나는 다른 브라우저에서 작동하도록 만들었지 만 iPhone을 사용하면 버튼을 누르고 있어야합니다. 단추를 누르고있을 때 기능을 반복 할 수있는 방법이 있습니까? 감사.JavaScript, iPhone : 버튼을 누른 채로 동작 반복

+0

나는 당신의 스페이스 인베이더 게임을 좋아합니다! – GlenCrawford

+0

사실, 바로 이것이 무엇을위한 것인가, 아이폰의 버튼을 누른 상태에서 촬영할 수 있어야합니다. – Doug

답변

0

버튼에서 보낸 touchDown 및 touchUpInside 메시지를 기반으로 타이머를 시작하고 중지하십시오. 버튼은 touchDown 및 touchUpInside 메서드를 아래 링크에 연결하도록 설정되어 있다고 가정합니다. 또는 "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 
+1

터치 다운이 버튼 안에 있지만 터치 업이 바깥입니까? – Olie

관련 문제