2014-12-08 9 views
0

다음 코드를 사용하여 간단한 게임을 만들기위한 버튼의 간단한 스케일 효과를 만듭니다. 사용자가 배율 조정 기간 내에 무언가로 연결되는 버튼을 터치하길 원합니다. 그 기간 내에 만지지 못하면 다른 일들이 일어납니다.애니메이션 도중 버튼 누름 감지

아래 코드를 사용하면 버튼이 애니메이션 완료 후 터치 만 감지 할 수 있습니다. 나는 정말로 원하지 않는다. 나는 그것이 애니메이션 중에 감지 될 수 있기를 원한다. 이 권리를 얻기 위해 어떤 코드를 사용해야합니까?

감사

-(void) start{ 
hit1= [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[hit1 addTarget:self action:@selector(rolebutton:) forControlEvents:UIControlEventTouchUpInside]; 
[hit1 setFrame:CGRectMake(575, 255, 45, 45)]; 
hit1.translatesAutoresizingMaskIntoConstraints = YES; 

[hit1 setBackgroundImage:[UIImage imageNamed:@"roles.png"] forState:UIControlStateNormal]; 
[hit1 setExclusiveTouch:YES]; 


hit1.transform = CGAffineTransformMakeScale(0.01, 0.01); 
[self.view addSubview:hit1]; 
[UIView animateWithDuration:1.0 
         delay:0.0 
        options:UIViewAnimationCurveEaseInOut 
       animations:^{ 
        hit1.transform = CGAffineTransformMakeScale(1, 1); 
        hit1.alpha = 1; 
       } 
       completion:^(BOOL finished){ 
        if (finished) 
        { 

         [hit1 removeFromSuperview]; 


         NSLog(@"customView Displayed ....."); 

        } 
       }]; 

}

-(void) rolebutton:(UIButton*) sender{ 
    NSLog(@"hit"); 



}/* 

답변

2

애니메이션 옵션 UIViewAnimationOptionAllowUserInteraction을 사용합니다.

-(void) start{ 
hit1= [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[hit1 addTarget:self action:@selector(rolebutton:) forControlEvents:UIControlEventTouchUpInside]; 
[hit1 setFrame:CGRectMake(575, 255, 45, 45)]; 
hit1.translatesAutoresizingMaskIntoConstraints = YES; 

[hit1 setBackgroundImage:[UIImage imageNamed:@"roles.png"] forState:UIControlStateNormal]; 
[hit1 setExclusiveTouch:YES]; 


hit1.transform = CGAffineTransformMakeScale(0.01, 0.01); 
[self.view addSubview:hit1]; 
[UIView animateWithDuration:1.0 
         delay:0.0 
        options:UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction 
       animations:^{ 
        hit1.transform = CGAffineTransformMakeScale(1, 1); 
        hit1.alpha = 1; 
       } 
       completion:^(BOOL finished){ 
        if (finished) 
        { 

         [hit1 removeFromSuperview]; 


         NSLog(@"customView Displayed ....."); 

        } 
       }];