2009-11-04 5 views
0

이전의 Simon 게임과 비슷하게 사용자에게 버튼 시퀀스 &을 표시 한 다음 다시 반복하도록하고 싶습니다. 내가 붙어있는 곳은 500ms 동안 강조 표시된 첫 번째 버튼을 보여 주며 100ms를 기다리며 500ms 동안 강조 표시된 두 번째를 표시하고 또 다른 100ms를 기다리며 세 번째 &을 표시합니다. 나는이 블록에 오긴했는데 다른 Stackoverflower'ers에서일련의 버튼을 강조 표시하려면 어떻게합니까?

:

redButton.highlighted = YES; 

[UIView beginAnimations:@"" context:nil]; 
[UIView setAnimationStartDate:[NSDate dateWithTimeIntervalSinceNow:1]]; 
[UIView setAnimationsEnabled:NO]; 
redButton.highlighted = NO; 
[UIView commitAnimations]; 

[UIView beginAnimations:@"" context:nil]; 
[UIView setAnimationStartDate: [NSDate dateWithTimeIntervalSinceNow:2]]; 
[UIView setAnimationsEnabled:NO]; 
blueButton.highlighted = YES; 
[UIView commitAnimations]; 

redButton 강조하지만, 후속 조치 중 어느 것도 발생하지.

답변

4

코어 애니메이션을 사용하여이를 수행하는 방법이있을 수 있지만 반드시 필요한 것은 아닙니다. 강조 표시된 속성에 애니메이션 효과를 적용하지 않고 그냥 켜고 끕니다.

타이머로이를 수행하는 간단한보기 기반 iPhone 응용 프로그램을 만들었습니다.

SimonTestViewController.h :

#import <UIKit/UIKit.h> 

@interface SimonTestViewController : UIViewController { 
IBOutlet UIButton *redButton; 
IBOutlet UIButton *blueButton; 
IBOutlet UIButton *greenButton; 
IBOutlet UIButton *yellowButton; 
} 

- (void)highlightButton:(UIButton*)button Delay:(double)delay; 
- (void)highlightOn:(NSTimer*)timer; 
- (void)highlightOff:(NSTimer*)timer; 

@end 

SimonTestViewController.m :

#import "SimonTestViewController.h" 

@implementation SimonTestViewController 

const double HIGHLIGHT_SECONDS = 0.5; // 500 ms 
const double NEXT_SECONDS = 0.6; // 600 ms 

- (void)viewDidAppear:(BOOL)animated { 
[super viewDidAppear:animated]; 

[self highlightButton:redButton Delay:0.0]; 
[self highlightButton:blueButton Delay:NEXT_SECONDS]; 
[self highlightButton:greenButton Delay:NEXT_SECONDS * 2]; 
[self highlightButton:blueButton Delay:NEXT_SECONDS * 3]; 
[self highlightButton:yellowButton Delay:NEXT_SECONDS * 4]; 
[self highlightButton:redButton Delay:NEXT_SECONDS * 5]; 
} 

- (void)highlightButton:(UIButton*)button Delay:(double)delay { 
[NSTimer scheduledTimerWithTimeInterval:delay target:self selector:@selector(highlightOn:) userInfo:button repeats:NO]; 
} 

- (void)highlightOn:(NSTimer*)timer { 
UIButton *button = (UIButton*)[timer userInfo]; 

button.highlighted = YES; 

[NSTimer scheduledTimerWithTimeInterval:HIGHLIGHT_SECONDS target:self selector:@selector(highlightOff:) userInfo:button repeats:NO]; 
} 

- (void)highlightOff:(NSTimer*)timer { 
UIButton *button = (UIButton*)[timer userInfo]; 

button.highlighted = NO; 
} 
여기서 뷰 컨트롤러의 코드는
관련 문제