This is a view for you to either subclass or use as-is. The view comes loaded with the ability to:
- Generate screen grab (ignoring itself)
- Blur the image - This is lifted from Apple's example
- Fake a live blur by scrolling the image in the opporsite direction of the motion
- It should just work! like magic!
Background:
Since Apple do not provide us with the blur that they use in their navigation controller, I created a view that mimics the live blur. As mention above, this is not a real live blur, but a fake one. Thus limitation is to be expected. The reason that I used the fake method because on-the-fly blur is very resource draining and laggy.
Implementation:
The view is a subclass of a UIView. It has a scrollView (X) that is not user interactable as its default background. This scrollView (X) scroll in the opporsite way of the scrollView (Y) that host this blurredView (superview). This behaviour gives the illusion that the BTBlurredView is blurring the background on the fly. In reality, the whole background was blurred only once.
How to use:
- Import
BTBlurredView.h
- Create an instance of blurredView
- Setup - If superview is not the background you want, specifically assign that to
backgroundView
iVar (Most of the time it is not) - Setup2 - If the default
relativeOrigin
is not good enough (I highly recommend you try the default before tinkering with it), assign it a better origin (your view origin w.r.t. the device screen) - Blur - You can implement the delegate or just mess with the file for different blur effect
- Live - Make sure when you scroll background, do an update to the view by calling (If the view is static, set
isStaticOnly
toYES
)
6a. scroll -(void)viewDidMoveToPointOffset:(CGPoint)pointOffset
6b. Alernatively, create an observer by settingshouldObserveScroll
toYES
and send notificationPARENT_SCROLL_NOTIFICATION
with the new contentOffset - change background -
(void)refreshBackground
(Alternatively you can assign your own flavour with the delegate(UIImage *)customBackgroundForBlurredView:(BTBlurredView *)blurredView
)
Please view example project to get the idea of how to implement.
Note:
-
(void)refreshBackgroundWithAnimationCode:(AnimationCode)animationCode duration:(CGFloat)duration
is an experimentation that did not quite take off. However, it still contains a pretty nice effect, so I left it in there. It allows the change in the background to have animation. Sadly, it cannot do a synchronized animation since the screen is not ready to be grabbed until the background is done animating. -
shouldUseExperimentOptimization
, if set toYES
, will try to determine if your view is within the bound of the device, if not, it will not update the background. This is done to optimize the use of the scrollView.