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
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:
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.
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