Lag while drawing in ios7

后端 未结 3 537
甜味超标
甜味超标 2021-02-04 21:33

I am having an app in which I am doing some sketching on a view.

So far, it was working fine until I installed ios7.

My app uses touches moved met

相关标签:
3条回答
  • 2021-02-04 22:08

    Here's listed same code with same problem on ios7 https://stackoverflow.com/questions/18198129/ios-7-making-my-apps-drawing-algorithm-lag people suggest moving drawing logic into drawRect:

    0 讨论(0)
  • 2021-02-04 22:12

    To find a instant solution, Replace this line

     mainImage.image = UIGraphicsGetImageFromContext(UIGraphicsGetCurrentContext());
    

    with

    [mainImage performSelectorInBackground:@selector(setImage:) withObject:UIGraphicsGetImageFromCurrentImageContext()];
    

    If you need an elaborate and accurate solution try to replace the MoveTo with CGMutablepath . Hope this helps.

    0 讨论(0)
  • 2021-02-04 22:16

    we have solved this problem using dispatch_async(dispatch_get_main_queue(), ^{)}; block in touchMoved method like this :

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
    
            dispatch_async(dispatch_get_main_queue(), ^{
            mouseSwiped = YES;
            UITouch *touch = [touches anyObject];
            if(touch.view==self.vwSwipePage)
            {
                return;
            }
            if(flagIsEraser)
            {
                CGPoint currentPoint;
                if(flagActiveViewPage)
                {
    
                    currentPoint = [touch locationInView:self.mainImage];
                    UIGraphicsBeginImageContext(self.mainImage.frame.size);
                    [self.mainImage.image drawInRect:CGRectMake(0, 0, self.mainImage.frame.size.width, self.mainImage.frame.size.height)];
                }
                else
                {
                    currentPoint = [touch locationInView:self.mainImage1];
                    UIGraphicsBeginImageContext(self.mainImage1.frame.size);
                    [self.mainImage1.image drawInRect:CGRectMake(0, 0, self.mainImage1.frame.size.width, self.mainImage1.frame.size.height)];
                }
    
                //clear using circle brush........
                CGContextRef context = UIGraphicsGetCurrentContext();
                CGContextSetLineCap(context, kCGLineCapRound);
                CGContextSetLineWidth(context,20);
                CGContextSetBlendMode(context, kCGBlendModeClear);
                CGContextSetStrokeColorWithColor(context, [[UIColor clearColor] CGColor]);
                CGContextBeginPath(context);
                CGContextMoveToPoint(context, lastPoint.x, lastPoint.y);
                CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y);
                CGContextStrokePath(context);
                CGContextFlush(context);
                if(flagActiveViewPage)
                    self.mainImage.image = UIGraphicsGetImageFromCurrentImageContext();
                else
                    self.mainImage1.image = UIGraphicsGetImageFromCurrentImageContext();
    
                UIGraphicsEndImageContext();
                lastPoint = currentPoint;
    
            }
        });
        }
    

    May this will Help u to solve ur problem.

    Thanks

    0 讨论(0)
提交回复
热议问题