嘿,我在构建应用程序方面需要帮助。我构建了一个艺术应用程序,这个应用程序正在处理干扰。这就是我需要在这个应用程序中画很多线的原因。更多的行对干扰更好。我认为问题是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
图片 http://img17.imageshack.us/img17/375/53178410200339197475308.jpg