2
나는 간단한 UIView의 backgroundColor로의 전환과 같은 자체 스레드에서 실행이 :UIView 애니메이션 지연이 없습니다!
- (void)colorLoop_thread {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// [self performSelector:@selector(changeColors)];
[self performSelectorOnMainThread:@selector(changeColors) withObject:nil waitUntilDone:NO];
[pool release];
}
- (void)changeColors {
if(self.colorStatus == colorBegin) {
self.backgroundColor = [self randomColor];
self.colorStatus = colorChanged;
}
if(self.colorStatus == colorChanged) {
self.colorStatus = colorChanging;
[UIView beginAnimations:@"ChangeColor" context:nil];
[UIView setAnimationDuration:2.0f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(changeColorFinished:finished:context:)];
self.backgroundColor = [self randomColor];
[UIView commitAnimations];
}
[NSTimer scheduledTimerWithTimeInterval:0.033 target:self selector:@selector(changeColors) userInfo:nil repeats:NO];
}
- (void)changeColorFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context {
if([animationID isEqualToString:@"ChangeColor"]) {
self.colorStatus = colorChanged;
}
}
하지만 ... 그것은 같은으로 초기화 후 실행시 :
colorStatus = colorBegin;
static BOOL colorThread = NO;if(!colorThread) {colorThread = YES;[NSThread detachNewThreadSelector:@selector(colorLoop_thread) toTarget:self withObject:nil];}
색상이 시간이 지남에 따라 변경되지 않습니다, 지연이 전혀없는 것처럼 애니메이션이 진행되며 배경이 너무 빠르게 변하여 간질 발작을 담당하는 기사에 따라 AppReviewers가 내 앱을 거부합니다. 누군가 제 시간에 애니메이션이 나오지 않고 플래시가 끝나는 이유를 이해하도록 도와주세요.
환영합니다. StackOverflow는 BBCode 대신 Markdown을 사용합니다. 소스 코드로 포맷하려면 4 칸이나 1 탭을 들여 씁니다. 형식 가이드는 http://stackoverflow.com/editing-help를 참조하십시오. – kennytm