这就是我想做的:
我有一个 UIBezierPath,我想将它传递给某种方法来绘制它。或者简单地从创建它的方法中提取它。
我不确定如何指示应在哪个视图中绘制它。所有绘图方法都必须以
- (void)drawRect:(CGRect)rect { ...} ?
我可不可以做
- (void)drawRect:(CGRect)rect withBezierPath:(UIBezierPath*) bezierPath { ... } ??
如何从另一个方法调用这个函数或方法?
drawRect:
当您发送消息时会自动调用setNeedsDisplay
or setNeedsDisplayInRect:
在一个视图上。你从不打电话drawRect:
直接地。
然而,你说得对,所有绘图操作都是在drawRect:
方法。典型的实现是,
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
/* Do your drawing on `context` */
}
既然你正在使用UIBezierPath
s,您将需要维护一组需要绘制然后调用的贝塞尔路径setNeedsDisplay
当事情发生变化时。
- (void)drawRect:(CGRect)rect {
for ( UIBezierPath * path in bezierPaths ) {
/* set stroke color and fill color for the path */
[path fill];
[path stroke];
}
}
where bezierPaths
是一个数组UIBezierPath
s.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)