嘿,我需要幫助建立一個應用程序。我構建了一個藝術應用程序,這個應用程序正在與干擾。這就是我需要在這個應用程序中繪製多條線的原因。干擾更多的線條更好。我認爲問題在於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