
为此,我试图从中心画一个圆圈和一系列线条,就像图表轮子中的光线一样.
我已成功绘制了圆圈,现在我想绘制将圆圈分成切片的线条.
这是我到目前为止:
-(voID)drawRect:(CGRect)rect{ [[UIcolor blackcolor] setstroke]; CGContextRef ctx = UIGraphicsGetCurrentContext(); CGfloat minDim = (rect.size.wIDth < rect.size.height) ? rect.size.wIDth : rect.size.height; CGRect circleRect = CGRectMake(0,rect.size.height/2-minDim/2,minDim,minDim); CGContextAddEllipseInRect(ctx,circleRect); CGContextSetFillcolor(ctx,CGcolorGetComponents([[UIcolor yellowcolor] CGcolor])); CGContextFillPath(ctx); CGPoint start = CGPointMake(0,rect.size.height/2); CGPoint end = CGPointMake(rect.size.wIDth,rect.size.height/2); for (int i = 0; i < MaxSlices(6); i++){ CGfloat degrees = 1.0*i*(180/MaxSlices(6)); CGAffinetransform rot = CGAffinetransformMakeRotation(degreesToradians(degrees)); UIBezIErPath *path = [self pathFrom:start to:end]; [path applytransform:rot]; } } - (UIBezIErPath *) pathFrom:(CGPoint) start to:(CGPoint) end{ UIBezIErPath* aPath = [UIBezIErPath bezIErPath]; aPath.linewidth = 5; [aPath movetoPoint:start]; [aPath addlinetoPoint:end]; [aPath closePath]; [aPath stroke]; return aPath;} 问题是路径上的applytransform似乎没有做任何事情.正确绘制的第一个路径和以下的路径不受旋转的影响.基本上我所看到的只是一条路.检查屏幕截图http://img837.imageshack.us/img837/9757/iossimulatorscreenshotf.png
谢谢您的帮助!
解决方法 在转换之前,您正在绘制路径(使用笔划).路径只是一种数学表示.它不是“在屏幕上”的线.您无法通过修改有关它的数据来移动您已绘制的内容.只需将[aPath笔划]移出pathFrom:to:并将其放在applytransform:之后:
总结以上是内存溢出为你收集整理的ios – UIBezierPath和applytransform全部内容,希望文章能够帮你解决ios – UIBezierPath和applytransform所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)