Shortly speaking:
LooksLike drawRectitself (even empty) leads to significant performance bottlenecks depending on the resolution of the device - a larger screen is worse. Is there a way to speed up the redrawing of view content?
More details:
I am creating a small drawing application on iOS - the user moves his finger on the screen to draw a line.
The idea of ββthis is quite simple - while the user moves his finger touchesMoved, accumulates changes to the on-screen buffer image and invalidates the view in order to combine the off-screen buffer with the contents of the view.
A simple piece of code might look like this:
@interface CanvasView : UIView
...
end;
@implementation CanvasView{
UIImage *canvasContentImage;
UIImage *bufferImage
CGContextRef drawingContext;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UIGraphicsBeginImageContext(canvasSize);
drawingContext = UIGraphicsGetCurrentContext();
...
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
CGContextMoveToPoint(drawingContext, prevPoint.x, prevPoint.y);
CGContextAddLineToPoint(drawingContext, point.x, point.y);
CGContextStrokePath(drawingContext);
...
[self setNeedDisplay];
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UIGraphicsEndImageContext();
...
}
-(void)drawRect:(CGRect)rect{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, self.bounds, canvasContentImage.CGImage);
CGContextDrawImage(context, imageRect, bufferImage.CGImage);
...
}
fps.
, ββ, 60 . fps . , iPad Retina 15-20 , .
, , setNeedsDisplay , . setNeedsDisplayInRect, . , ( ).
, , . , fps 15-20 - , .
, drawRect, fps 60. , , . , :
, drawRect touchMoved, , drawRect - 60 .
, drawRect .
, , pregenerated drawRect:
" drawRect: . ".
, , drawRect , " "
, :
drawRect, , drawRect - ?
, ? OpenGL , /, .
.
!
EDIT:
UIImageView . ( 19-22 ). 50-60 .
, , - - , 60 .
UIImageView.image, , fps 19-22. , , .
, - (UIImageView), ?