心寄笔端 附庸风雅

甘草的技术博客

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

我感觉,这个可以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

  

posted on 2012-01-19 17:09  甘草  阅读(1549)  评论(0编辑  收藏  举报
Baidu
Google
心寄笔端
TEST
以后我会加上Power By的,先别介意