Lag while drawing in ios7

后端 未结 3 541
甜味超标
甜味超标 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: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

提交回复
热议问题