Reputation: 2268
Ok, I have a serious problem with ios7. I have a code where the user drags a control, and as he drags, the interface is updated with a processed image. This was very fast until iOS 6.1, and now it's very slow.
Here's how my code works:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//get initial position
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
//calculates new position
applyEffects();
- (void)applyEffects {
UIGraphicsBeginImageContext();
//CGContextTranslateCTM, CGContextScaleCTM, CGContextDrawImage and stuff like that
UIImage *blendedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
preview.image = blendedImage; //preview is a UIImageView
Now the thing is, after logging, I realized applyEffects is getting called every time I move the finger on screen, but the view is being updated very very few times, and I think that's why it appears so slow.
So, any idea on why "preview.image = blendedImage;" is not updating the view anymore? Am I missing something?
Again, this only happens on iOS 7.
Thank you in advance!
Upvotes: 3
Views: 1304
Reputation: 2268
Changed my applyEffects to this:
dispatch_queue_t myQueue = dispatch_queue_create("My Queue",NULL);
if (!running) {
running = true;
dispatch_async(myQueue, ^{
UIGraphicsBeginImageContext();
//CGContextTranslateCTM, CGContextScaleCTM, CGContextDrawImage and stuff like that
UIImage *blendedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
dispatch_async(dispatch_get_main_queue(), ^{
// Update the UI
preview.image = blendedImage;
running = false;
});
});
}
Now it will create a separate thread to apply the effect, and update the UI when it's ready. This way I'm not clogging up the UI touch event processing.
The if (!running) is a dumb control to make it only run once at a time.
The ideal way is to throw away all that code and reimplement it with GPUImage, but it will require much more time, so it's a temporary solution.
Upvotes: 2