1

任何人都可以在这段代码中看到一些东西,让它在 iPhone 上运行得非常柔和,但在 iPad 上的视网膜和非视网膜上却又慢又不稳定/笨拙?关于如何加快 iPad 速度的任何想法?我只想让它基本上用手指绘画,控制画笔大小、不透明度和边缘(这就是为什么我有渐变,用于软边缘)

谢谢

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

    UITouch *touch = [touches anyObject];
    CGPoint currentPointTemp = [touch locationInView:parentView.view];
    CGPoint currentPoint = CGPointMake((currentPointTemp.x /imageScale)+ (posOffset.x/imageScale), (currentPointTemp.y /imageScale) + (posOffset.y/imageScale));
    currentPoint.y -= 10;

    UIGraphicsBeginImageContextWithOptions(CGSizeMake(drawImage.frame.size.width, drawImage.frame.size.height), NO, 0); 

    [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)];

    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetAlpha(UIGraphicsGetCurrentContext(), opacity);
    CGContextBeginPath (UIGraphicsGetCurrentContext());
    CGContextAddArc(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y, glamzyDelegate.brushSize, 0, 6.28318531, 0);
    CGContextClosePath (UIGraphicsGetCurrentContext()); 
    CGContextClip(UIGraphicsGetCurrentContext());

    CGPoint myStartPoint, myEndPoint;
    CGFloat myStartRadius, myEndRadius;
    myStartPoint.x = lastPoint.x;
    myStartPoint.y =  lastPoint.y;
    myEndPoint.x = lastPoint.x;
    myEndPoint.y =  lastPoint.y;
    myStartRadius = 0;
    myEndRadius = glamzyDelegate.brushSize;

    CGContextDrawRadialGradient(UIGraphicsGetCurrentContext(), gradient, myStartPoint, myStartRadius, myEndPoint, myEndRadius, kCGGradientDrawsAfterEndLocation);

    drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    lastPoint = currentPoint;
}
4

1 回答 1

0

永远不要在触摸事件中调用任何绘图例程。

  1. 您应该覆盖视图的drawrect方法
  2. 在触摸事件中调用 setneedsdisplay
于 2012-06-21T16:30:26.493 回答