0

Is this the quickest way to blur a view - because for my view (UICollectionView of images) it's too slow for good UX - any tips on performance improvements, better methods?

I tried altering the scale on the BeginImageContext method (third variable), with little change in performance.

(import category on UIImage from Apple)
#UIImage+ImageEffects.h 

- (UIImage*)blurViewToImage:(UIView *)view type:(int)type {

//0 -dark
//1 -light
//2 -extra light

UIGraphicsBeginImageContextWithOptions(view.frame.size, true, 0.0f);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:false];
UIImage * snappy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

switch (type) {
    case 0:
        return [snappy applyDarkEffect];
        break;
    case 1:
        return [snappy applyLightEffect];
        break;
    case 2:
        return [snappy applyExtraLightEffect];
        break;
    default:
        break;
}

return nil;
}
Johnny Rockex
  • 4,136
  • 3
  • 35
  • 55

1 Answers1

1

You may want to have a look at this on StackOverflow

If this won't suit your needs try to call the function

- (UIImage*)blurViewToImage:(UIView *)view type:(int)type

in a separate Thread, so your UI keeps usable:

[self performSelectorInBackground:(SEL) withObject:(id)]
Community
  • 1
  • 1
Maurice
  • 1,466
  • 1
  • 13
  • 33
  • thanks - I'd normally run it on a background thread but then it'd take longer, plus the background can change but is static when the user calls it, so I can't preload images either. It's funny that the best solution is to trick UIToolbar into being a background. At least with iOS8 we get more power. – Johnny Rockex Jul 25 '14 at 08:39