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.
分享到:
相关推荐
IOS中drawRect方法的使用, 在需要重绘的时调用setNeedsDisplay方法
setNeedsDisplay会调用自动调用drawRect方法,这样可以拿到UIGraphicsGetCurrentContext,就可以画画了。而setNeedsLayout会默认调用layoutSubViews,就可以处理子视图中的一些数据。 宗上所诉,setNeedsDisplay...
在iOS中,利用UIView绘图,重写UIView的drawRect方法,点用setNeedsDisplay方法系统会自动调用drawRect完成绘图。(北京智美方成网络科技有限公司面试题), 详细说明: https://a3.work/a/oc/106.html
核心代码,使用UIImageView实现触摸绘图, 比起使用数组实现要强很多, 使用数组会很费内存,高手请过。minixx新手学习资料保存 //监听触摸事件 -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ ...
鹏哥哥放大镜 封装好 线程安全 无泄漏 简单易用 移植性好 使用中有问题 请前去GitHub与我联系 感谢您的使用 对您有帮助的话 送我一颗星星可好 使用简介: 1.PGGMagnigierView导入放大镜类 也可以在这里面进行镜框...
对于动态创建的UI布局或在运行时可以更改的UI布局,或者通过查找非透明视图或不必要重绘的视图来调整性能,该功能尤其有用。 它设计用于iPhone模拟器,但也可以在设备上使用。 它使用键盘快捷键来处理开始,结束和...
或动态,其将在背景上自动重绘自身尽可能多地线程化。 支持的iOS和SDK版本 支持的构建目标-iOS 8.4(Xcode 6.4,Apple LLVM编译器6.1) 支持的最早部署目标-iOS 7.0 最早兼容的部署目标-iOS 4.3 注意:“受支持”...
view层主要处理,包括(九个按钮)touchesBegan,touchesMoved,touchesEnded,点与点之间画线,手指滑动画线,画线主要是在drawRect中重绘,提到这里必须不能忘记setNeedsDisplay这个方法。还要记录经过的按钮...
1.2、当手指接触屏幕时,调用重写的 touchesBegan:withEvent方法(在touchesBegan里调用setNeedsDisplay,这样就会自动调用drawRect方法)。 1.3、当手指在屏幕上滑动时,调用重写的touchesEnded:withEvent方法。 ...
SetNeedsDisplay此软件包提供了可用于任何NSView或UIView的属性的属性包装器,以使布局或显示无效SetNeedsDisplay此软件包提供了可用于任何NSView或UIView的属性的属性包装器,以使布局或显示值无效所述属性的更改。...
截屏操作环境iOS7~如何使用添加到要显示 ArcView 的视图控制器。 self.arc = [[ArcView alloc ] initWithFrame: self .view.frame]; [ self .view addSubview: self .arc]; 通过传递 0 到 1 之间的值进行绘制。 // ...
ODUIThreadGuard ODUIThreadGuard是一种保护措施,可帮助您检查是否在主线程中未进行UI更改。 由于Xcode 9将此功能嵌入到Xcode中,...功能被动实现如果setNeedsDisplay,setNeedsLayout或setNeedsDisplayInR引发断言
饼形图用 Swift 制作的简单饼图 例子: let pieChartView = PieChartView(frame: CGRectMake(0, 0, 300, 200)) pieChartView...pieChartView.addItem(60, color: UIColor.brownColor()) pieChartView.setNeedsDisplay()