Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPad上的iOS绘图速度很慢,但iPhone是完美的_Iphone_Ios_Ipad_Drawing_Paint - Fatal编程技术网

iPad上的iOS绘图速度很慢,但iPhone是完美的

iPad上的iOS绘图速度很慢,但iPhone是完美的,iphone,ios,ipad,drawing,paint,Iphone,Ios,Ipad,Drawing,Paint,有没有人能从这段代码中看到一些东西,让它在iPhone上运行得很软,但在iPad上无论是视网膜还是非视网膜上都运行得很慢、有斑点/矮胖?有没有关于如何加快iPad速度的想法?我只想让它基本上用手指画画,控制画笔大小、不透明度和边缘(这就是为什么我有渐变,用于软边) 多谢各位 -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject];

有没有人能从这段代码中看到一些东西,让它在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;
}

切勿在触摸事件中调用任何绘图例程

  • 应该重写视图的drawrect方法
  • 呼叫设置需要在触摸事件中显示

  • 这是一个有趣的问题。我很想知道出了什么问题。你在设备上测试过吗?或者你的观察是基于模拟器的性能?这是有趣的事情。在iPad模拟器上,它也很流畅。iPad和iPhone模拟器平滑,iPhone设备,iPodtouch,也平滑。iPad设备,不那么火爆,不起眼,速度也不慢。如果你真的感兴趣,你可以下载该应用程序。这段代码在Glamzy中运行,Glamzy为iPhone和iPad提供免费版本。我原以为这可能是视网膜的问题,但在iPad2上听到了这方面的报道(我只有retina iPad),这可能归结为一种更好的方式来做渐变或软边刷。谢谢你的关注!这只是把它从一个板块推到另一个板块——不管你是在touchesMoved还是drawRect中绘制,代码都在阻止用户交互的主线程上运行。我可能错了,但我很确定使用drawRect在性能上不会有任何差异。可能是,但是图形上下文呢?文档中有这样一句话:“在调用其drawRect:方法之前,视图对象将有效上下文推送到堆栈上,使其成为当前上下文。但是,如果您没有使用UIView对象进行绘图,则必须使用UIGraphicsPushContext函数手动将有效上下文推送到堆栈上。”将draw代码放在drawRect中没有明显的改进。我将把它放在那里,因为它似乎是一个商定的标准。还有其他关于如何在iPad上加速的想法吗?有没有人知道一个更好的方法来画一个软边,可能是梯度太贵了。(即将测试非渐变图形)