我感觉,这个可以Win32里面的while( PeekMessage( ... ) )是一会儿事情。比较简单。
CFRunLoopRun();就完成了这个事情。
那么如何解除这个Block呢?
可以用这个:
CFRunLoopStop( someLoop );
someLoop可以通过CFRunLoopGetCurrent()函数来获得。
这样就可以轻易地等待各种线程了,比如说动画线程。
@interface UIViewDelegate : NSObject
{
CFRunLoopRef _currentLoop;
}
@end
@implementation UIViewDelegate
-(id) init:(CFRunLoopRef)runLoop
{
if (self = [super init])
_currentLoop = runLoop;
return self;
}
-(void) animationFinished: (id) sender
{
CFRunLoopStop(_currentLoop);
}
@end
@implementation UIView (Block)
+ (void) commitAnimationsAndBlock
{
CFRunLoopRef currentLoop = CFRunLoopGetCurrent();
UIViewDelegate *delegate = [[UIViewDelegate alloc] init:currentLoop];
[UIView setAnimationDelegate:delegate];
[UIView setAnimationDidStopSelector:@selector(animationFinished:)];
[UIView commitAnimations];
CFRunLoopRun();
[delegate release];
}
@end
转载:http://www.cnblogs.com/healerkx/archive/2012/01/19/2327521.html