2012-06-21 45 views
1

任何人都可以在此代码中看到允许其在iPhone上使用黄油柔软的东西,但是iPad和retina和非ipad上的缓慢和斑点/厚块?有关如何加速iPad的任何想法?我只是希望它的手指油漆基本上,有超过画笔大小,不透明度和边缘控制(这就是为什么我有梯度,软边)在iPad上绘图的速度很慢,但iPhone是完美的

谢谢

-(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; 
} 
+0

这是一个有趣的问题

  • 呼叫setneedsdisplay视图的drawRect方法。我很想知道发生了什么问题。你有没有在设备上测试过它?或者你的观察是基于模拟器的性能? – Ravi

  • +0

    那就是有趣的事情。在iPad模拟器上,它也很流畅。 iPad和iPhone模拟器流畅,iPhone设备,iPod touch也顺畅。 iPad设备,不那么热,多斑点和缓慢。如果你真的感兴趣,你可以下载应用程序。这段代码运行在Glamzy中,它有一个适用于iPhone和iPad的免费版本。我认为这可能是一个视网膜问题,但在iPad 2上听到这个报道(我只有视网膜iPad)它可能会降低到一个更好的方式来做一个渐变或软边刷。感谢您的关注! –

    回答

    0

    ,一定不要调用在任何绘图程序触摸事件。

    1. 你应该覆盖的触摸事件
    +2

    这只是将它从板的一侧推向另一侧 - 无论您是在touchesMoved还是drawRect中绘制,代码在主线程上运行以阻止用户交互。我可能是错的,但我敢肯定你不会看到任何使用drawRect的性能差异。 – davehayden

    +0

    可能是,但图形上下文呢?该文档有这样的说法: “在调用drawRect:方法之前,视图对象将有效的上下文推送到堆栈上,使其成为最新的。但是,如果您没有使用UIView对象来执行绘图,使用UIGraphicsPushContext函数手动将有效的上下文加载到堆栈上。“ –

    +0

    把绘图代码放在drawRect中没有什么明显的改进。我会把它留在那里,因为它看起来像是一个商定的标准。有关如何在iPad上加速的其他想法?有没有人知道一个更好的方法来绘制一个软边,可能是梯度太昂贵。 (将尽快测试非梯度图) –

    相关问题