Оптимизация CoreGraphics

У меня есть этот код, который работает очень медленно на iPad (по какой-то причине намного быстрее на iPhone):

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

[self.navigationController setNavigationBarHidden:YES animated:NO];

mouseSwiped = YES;
UITouch *touch = [touches anyObject];   
currentPoint = [touch locationInView:frontgroundView];

CGContextBeginPath(context);
CGContextMoveToPoint(context, lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y);
CGContextStrokePath(context);

maskRef = CGBitmapContextCreateImage(context);  

CGImageRef masked = CGImageCreateWithMask([backgroundImage CGImage], maskRef);
CGImageRelease(maskRef);

CGContextRef drawContext = UIGraphicsGetCurrentContext();

CGContextSaveGState(drawContext);
CGContextTranslateCTM (drawContext,0,frontgroundView.frame.size.height);
CGContextScaleCTM (drawContext, 1,-1);

CGContextDrawImage(drawContext, CGRectMake(0, 0, frontgroundView.frame.size.width, frontgroundView.frame.size.height), [frontgroundView.image CGImage]);

CGContextRestoreGState (drawContext);

CGContextDrawImage(drawContext, CGRectMake(0, 0, frontgroundView.frame.size.width, frontgroundView.frame.size.height), masked);

CGImageRef finalImage = CGBitmapContextCreateImage(drawContext);
frontgroundView.image = [UIImage imageWithCGImage:finalImage];
CGImageRelease(finalImage);

CGImageRelease(masked);

lastPoint = currentPoint;

mouseMoved++;

if (mouseMoved == 10)
    mouseMoved = 0;
}

Любые идеи??


person Adrian Sarli    schedule 16.12.2010    source источник
comment
Да, используйте Инструменты или хотя бы расскажите, что вы пробовали.   -  person Mike Abdullah    schedule 17.12.2010
comment
Я бы рекомендовал использовать инструмент CoreAnimation, чтобы посмотреть, что занимает много времени, или задать более конкретный вопрос.   -  person Sam Soffes    schedule 15.03.2011


Ответы (1)


Вы должны рисовать в -drawRect: для вашего представления, а не непосредственно в ответ на прикосновение.

person Ben Stiglitz    schedule 01.04.2011
comment
используйте ` [self setNeedsDisplay] ` или ` [self setNeedsLayout] ` в вашем методе - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event - person Abhishek Bedi; 29.11.2012