我的这段代码在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;
}
任何想法??
答案 0 :(得分:0)
你应该在-drawRect中绘图:为你的视图而不是直接回应触摸。