Skip to content

nicolastinkl/BlurryModalSegue

 
 

Repository files navigation

BlurryModalSegue

BlurryModalSegue is a UIStoryboardSegue subclass that provides a blur effect for modal storyboard segues. It provides the look and feel of a transparent modal overalay without deviating from the modal presentation model provided by Apple.

Demo

Installation

Via Cocoapods:

pod 'BlurryModalSegue'

Usage

Storyboard Usage

Change your modal storyboard segues from this:

To this:

Done!

Custom Styling

BlurryModalSegue conforms to the UIAppearance protocol. Configure it once across the app:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[BlurryModalSegue appearance] setBackingImageBlurRadius:@(20)];
    [[BlurryModalSegue appearance] setBackingImageSaturationDeltaFactor:@(.45)];
    
    return YES;
}

Additionally, you can customize individual instances before presentation, just implement prepareForSegue:sender::

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue isKindOfClass:[BlurryModalSegue class]])
    {
        BlurryModalSegue* bms = (BlurryModalSegue*)segue;
        
        bms.backingImageBlurRadius = @(20);
        bms.backingImageSaturationDeltaFactor = @(.45);
        bms.backingImageTintColor = [[UIColor greenColor] colorWithAlphaComponent:.1];
    }
}

Compatibility/Restrictions

  • iOS7+ only, as we take advantage of the new UIViewControllerTransitionCoordinator.
  • Only UIModalTransitionStyleCoverVertical is supported right now.
  • Eagle-eyed developers will notice that the effect is better during presentation than dismissal. This is because UIViewController -(id<UIViewControllerTransitionCoordinator>)transitionCoordinator only seems to support the presentation, not the dismissal. I believe the dismissal could be implented using the UIViewController -(id<UIViewControllerTransitioningDelegate>)transitioningDelegate, but that is TBD.
  • Rotation is not supported.

Acknowledgements

About

A custom segue for providing a blurred overlay effect.

Resources

License

Stars

Watchers

Forks

Packages

No packages published