首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

iphone多线程应用setNeedsDisplay重绘drawRect

2012-08-27 
iphone多线程使用setNeedsDisplay重绘drawRectuiview子类{初始化方法-(id)initWithFrame:(CGRect)frame{初

iphone多线程使用setNeedsDisplay重绘drawRect
uiview子类{
初始化方法
-(id)initWithFrame:(CGRect)frame{
初始化类变量
t=[test new];
}

//前台绘画
-(void)drawRect:(CGRect)rect{
可以访问t变量
if(t != nil){
获取context
}
}
//后台读取数据
-(void)read{


}

-(void)run{
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
[self performSelectorOnMainThread:@selector(setNeedsDisplay) vithObject:nil waitUntilDon:NO];
[NSThread sleepForTimeInterval:0.5];
[pool drain];
}


-(void)start{
NSThread *drawUI=[[NSThread alloc] initWithTarget:self selector:@selector(run) object:nil];
[drawUI start];

NSThread *readn=[[NSThread alloc] initWithTarget:self selector:@selector(read) object:nil];
[readn start];

}
}

注意这个方法中的initWithFrame,如果不用这个方法初始化,重绘drawRect的时候类变量t的计数会为0.



热点排行