嘿,我需要帮助建立一个应用程序。我构建了一个艺术应用程序,这个应用程序正在与干扰。这就是我需要在这个应用程序中绘制多条线的原因。干扰更多的线条更好。我认为问题在于iPad无法处理太多线条,因为速度或性能太慢。 我不知道如何加快我的代码在iPad上的更多性能。我应该使用Open GL还是其他什么...用性能绘制很多线条
我该怎么办?
这里是Draw.m
#import "Draw.h"
@implementation Draw
- (IBAction) sliderValueChanged:(UISlider *)sender {
label.text = [NSString stringWithFormat:@"%f", slider.value];
//NSLog(@"slider value = %f", sender.value);
[self setNeedsDisplay];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
//NSLog(@"slider value = %f", self.bounds.size.width);
CGMutablePathRef cgpath = CGPathCreateMutable();
CGPathMoveToPoint(cgpath, NULL, 0, 500);
CGMutablePathRef cgpath2 = CGPathCreateMutable();
CGPathMoveToPoint(cgpath2, NULL, 0, 500);
UIBezierPath *uipath = [[UIBezierPath alloc] init];
[uipath moveToPoint:CGPointMake(0, 0)];
int step = 5;
int iterations = self.bounds.size.width/step;
for (int i = 0; i < iterations+1; i++){
//CGPathAddCurveToPoint(cgpath, NULL, 1+i, 0, 1+i, 0, 1+i ,0);
CGPathAddLineToPoint (cgpath, NULL, 0, 0);
CGPathAddLineToPoint (cgpath, NULL, 0, 768);
CGPathAddLineToPoint (cgpath, NULL, step*i-slider.value*2, 768);
CGPathAddLineToPoint (cgpath, NULL, step*i, 0);
CGPathAddLineToPoint (cgpath, NULL, (step*i)+step, 0);
[[UIColor blackColor] setStroke];
CGContextAddPath(ctx, cgpath);
[self strokeUIBezierPath:uipath];
CGPathRelease(cgpath);
}
- (void)strokeContext:(CGContextRef)context
{
CGContextStrokePath(context);
}
- (void)strokeUIBezierPath:(UIBezierPath*)path
{
[path stroke];
}
@end
image http://img17.imageshack.us/img17/375/53178410200339197475308.jpg
你可以请张贴你想要画的一张或两张图片(用不同的滑块值)吗?这将有助于找出更好的方法来绘制它。 – 2013-04-10 21:39:08
此外,您的代码似乎不正确。你永远不会调用'strokeContext(context)',所以CGPath永远不会被执行。然而,你正在调用'strokeUIBezierPath:',其中没有行的Bezier路径,你永远不会修改它。 – 2013-04-10 21:42:07
这里从模拟器的屏幕截图http://img17.imageshack.us/img17/375/53178410200339197475308.jpg 当前的滑块控件的干扰... 该代码是在实验时刻,但我认为这是不是主要问题... – greenchapter 2013-04-10 22:50:53