diff --git a/MaryPopin.podspec b/MaryPopin.podspec index 30c4528..88819c9 100644 --- a/MaryPopin.podspec +++ b/MaryPopin.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "MaryPopin" - s.version = "1.3.1" + s.version = "1.4" s.summary = "Category to display modal-like view controllers with more options" s.description = <<-DESC @@ -17,7 +17,7 @@ Pod::Spec.new do |s| s.platform = :ios, '5.0' - s.source = { :git => "https://github.com/Backelite/MaryPopin.git", :tag => "1.3.1" } + s.source = { :git => "https://github.com/Backelite/MaryPopin.git", :tag => "1.4" } s.source_files = 'MaryPopin/**/*.{h,m}' diff --git a/MaryPopin/UIViewController+MaryPopin.h b/MaryPopin/UIViewController+MaryPopin.h index 1af7c7c..ce79409 100644 --- a/MaryPopin/UIViewController+MaryPopin.h +++ b/MaryPopin/UIViewController+MaryPopin.h @@ -23,6 +23,30 @@ #import +/** + * Object to customize blurry background + */ +@interface BKTBlurParameters : NSObject +/** + * Property to customize background view alpha. + */ +@property (assign, nonatomic) CGFloat alpha; +/** + * Property to customize background view blur radius. + */ +@property (assign, nonatomic) CGFloat radius; +/** + * Property to customize background view blur saturation factor. + * A value of 1.0 is neutral. Below it is desaturated and above it is more saturated. + */ +@property (assign, nonatomic) CGFloat saturationDeltaFactor; +/** + * Property to customize blur tint color. Default is clear color. + */ +@property (strong, nonatomic) UIColor *tintColor; + +@end + /** * Transition styles available when presenting popin view controllers. * @since v1.0 @@ -103,6 +127,10 @@ typedef NS_OPTIONS(NSUInteger, BKTPopinOption) { * Takes a screenshot of presenting view, blurs it and uses it as dimming view. Available only on ios 7.x. */ BKTPopinBlurryDimmingView = 1 << 2, + /** + * Disable parallax effect on iOS7 + */ + BKTPopinDisableParallaxEffect = 1 << 3, /** * Set a background dimming view with a clear color. Default is a semi-transparent black background */ @@ -332,4 +360,22 @@ typedef NS_ENUM(NSInteger, BKTPopinAlignementOption) { * @since v1.3 */ - (void)setPopinAlignment:(BKTPopinAlignementOption)popinAlignment; + +/** + * An object used to configure the blurred background. + * + * @return The blur parameters object. + * @see -setBlurParameters: + * @since v1.4 + */ +- (BKTBlurParameters *)blurParameters; + +/** + * An object used to configure the blurred background. + * + * @param blurParameters The blur parameters object. + * @sicne v1.4 + */ +- (void)setBlurParameters:(BKTBlurParameters *)blurParameters; + @end diff --git a/MaryPopin/UIViewController+MaryPopin.m b/MaryPopin/UIViewController+MaryPopin.m index 3f7da3d..ed9c526 100644 --- a/MaryPopin/UIViewController+MaryPopin.m +++ b/MaryPopin/UIViewController+MaryPopin.m @@ -93,6 +93,21 @@ CG_INLINE CGRect BkRectInRectWithAlignementOption(CGRect myRect, CGRect refRe } } + +@implementation BKTBlurParameters +- (id)init +{ + self = [super init]; + if (self) { + self.alpha = 1.0f; + self.radius = 20.f; + self.saturationDeltaFactor = 1.8f; + self.tintColor = [UIColor clearColor]; + } + return self; +} +@end + @interface UIImage (MaryPopinBlur) - (UIImage *)marypopin_applyBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage; @@ -130,8 +145,10 @@ - (void)presentPopinController:(UIViewController *)popinController fromRect:(CGR [dimmingView setBackgroundColor:[UIColor clearColor]]; } else if (options & BKTPopinBlurryDimmingView && [self.view respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) { UIImage *bgImage = [self createImageFromView:self.view]; - bgImage = [bgImage marypopin_applyBlurWithRadius:20.0 tintColor:[UIColor clearColor] saturationDeltaFactor:1.8 maskImage:nil]; + BKTBlurParameters *parameters = [popinController blurParameters]; + bgImage = [bgImage marypopin_applyBlurWithRadius:parameters.radius tintColor:parameters.tintColor saturationDeltaFactor:parameters.saturationDeltaFactor maskImage:nil]; UIImageView *bgImageView = [[UIImageView alloc] initWithImage:bgImage]; + bgImageView.alpha = parameters.alpha; [dimmingView addSubview:bgImageView]; } else { [dimmingView setBackgroundColor:[UIColor colorWithWhite:0.0f alpha:0.1f]]; @@ -395,7 +412,10 @@ - (void)addPopinToHierarchy:(UIViewController *)popinController UIViewAutoresizingFlexibleBottomMargin]; //Add motion effect - [UIViewController registerParalaxEffectForView:popinController.view WithDepth:10.0f]; + BKTPopinOption options = [popinController popinOptions]; + if (NO == (options & BKTPopinDisableParallaxEffect)) { + [UIViewController registerParalaxEffectForView:popinController.view WithDepth:10.0f]; + } [self.view addSubview:popinController.view]; //Create animator if needed @@ -411,18 +431,27 @@ - (void)addPopinToHierarchy:(UIViewController *)popinController - (void)forwardAppearanceBeginningIfNeeded:(UIViewController *)popinController appearing:(BOOL)isAppearing animated:(BOOL)animated { - if ([self shouldAutomaticallyForwardAppearanceMethods] == NO) { + if ([self bk_shouldAutomaticallyForwardAppearanceMethods] == NO) { [popinController beginAppearanceTransition:isAppearing animated:animated]; } } - (void)forwardAppearanceEndingIfNeeded:(UIViewController *)popinController { - if ([self shouldAutomaticallyForwardAppearanceMethods] == NO) { + if ([self bk_shouldAutomaticallyForwardAppearanceMethods] == NO) { [popinController endAppearanceTransition]; } } +- (BOOL)bk_shouldAutomaticallyForwardAppearanceMethods +{ + if ([self respondsToSelector:@selector(shouldAutomaticallyForwardAppearanceMethods)]) { + return [self shouldAutomaticallyForwardAppearanceMethods]; + } + + return [self automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers]; +} + + (void)registerParalaxEffectForView:(UIView *)aView WithDepth:(CGFloat)depth; { if ([aView respondsToSelector:@selector(motionEffects)]) { @@ -519,6 +548,21 @@ - (void)setPopinOptions:(BKTPopinOption)popinOptions objc_setAssociatedObject(self, @selector(popinOptions), [NSNumber numberWithInt:popinOptions], OBJC_ASSOCIATION_RETAIN_NONATOMIC); } +- (BKTBlurParameters *)blurParameters +{ + BKTBlurParameters *param = objc_getAssociatedObject(self, _cmd); + if (nil == param) { + return [[BKTBlurParameters alloc] init]; + } + + return param; +} + +- (void)setBlurParameters:(BKTBlurParameters *)blurParameters +{ + objc_setAssociatedObject(self, @selector(blurParameters), blurParameters, OBJC_ASSOCIATION_RETAIN_NONATOMIC); +} + - (void (^)(UIViewController * popinController,CGRect initialFrame,CGRect finalFrame))popinCustomInAnimation { return objc_getAssociatedObject(self, _cmd); @@ -542,7 +586,6 @@ - (void)setPopinCustomOutAnimation:(void (^)(UIViewController * popinController, - (BKTPopinAlignementOption)popinAlignment { - id storedValue = objc_getAssociatedObject(self, _cmd); return [objc_getAssociatedObject(self, _cmd) intValue]; } diff --git a/MaryPopinDemo/MaryPopinDemo/BKTViewController.m b/MaryPopinDemo/MaryPopinDemo/BKTViewController.m index f179bc9..d610a2d 100644 --- a/MaryPopinDemo/MaryPopinDemo/BKTViewController.m +++ b/MaryPopinDemo/MaryPopinDemo/BKTViewController.m @@ -62,6 +62,14 @@ - (IBAction)presentPopinPressed:(id)sender { //Set popin alignement according to value in segmented control [popin setPopinAlignment:self.selectedAlignementOption]; + //Create a blur parameters object to configure background blur + BKTBlurParameters *blurParameters = [BKTBlurParameters new]; + blurParameters.alpha = 1.0f; + blurParameters.radius = 8.0f; + blurParameters.saturationDeltaFactor = 1.8f; + blurParameters.tintColor = [UIColor colorWithRed:0.966 green:0.851 blue:0.038 alpha:0.2]; + [popin setBlurParameters:blurParameters]; + //Add option for a blurry background [popin setPopinOptions:[popin popinOptions]|BKTPopinBlurryDimmingView]; diff --git a/README.md b/README.md index 3054278..5968000 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ MaryPopin ========= +[![License MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/Backelite/MaryPopin/blob/master/LICENSE) +[![Release](http://img.shields.io/github/release/Backelite/MaryPopin.svg)](https://github.com/Backelite/MaryPopin) +[![CocoaPods](http://img.shields.io/cocoapods/v/MaryPopin.svg)](https://github.com/Backelite/MaryPopin) MaryPopin is a category on `UIViewController` to present modal like controller with more flexibility. @@ -28,6 +31,11 @@ that is why we name it a popin controller. And as it is implemented as a categor ========= ## Changes +v1.4 +* Added an option to configure blur background +* Fixed a crash with iOS 5.x +* Fixed an unused variable warning + v 1.3.1 * Fixed an issue with default alignment option @@ -124,7 +132,7 @@ If you are using CocoaPods in version 0.29 or better, you can quickly run the de pod try MaryPopin ## Requirements -MaryPopin requires Xcode 5 as it uses (optionaly) UIKit Dynamics and motion effects. You can use iOS 5 as a target deployment version. Note that some transition styles are not supported under iOS 7 and will be replaced by the default transition style. +MaryPopin requires Xcode 5 as it uses (optionally) UIKit Dynamics and motion effects. You can use iOS 5 as a target deployment version. Note that some transition styles are not supported under iOS 7 and will be replaced by the default transition style. ### ARC MaryPopin uses ARC.