Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaspard Viot committed May 16, 2014
2 parents 5ed860a + d1d092d commit baa27d6
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 8 deletions.
4 changes: 2 additions & 2 deletions MaryPopin.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}'

Expand Down
46 changes: 46 additions & 0 deletions MaryPopin/UIViewController+MaryPopin.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@

#import <UIKit/UIKit.h>

/**
* 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
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
53 changes: 48 additions & 5 deletions MaryPopin/UIViewController+MaryPopin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]];
Expand Down Expand Up @@ -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
Expand All @@ -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)]) {
Expand Down Expand Up @@ -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);
Expand All @@ -542,7 +586,6 @@ - (void)setPopinCustomOutAnimation:(void (^)(UIViewController * popinController,

- (BKTPopinAlignementOption)popinAlignment
{
id storedValue = objc_getAssociatedObject(self, _cmd);
return [objc_getAssociatedObject(self, _cmd) intValue];
}

Expand Down
8 changes: 8 additions & 0 deletions MaryPopinDemo/MaryPopinDemo/BKTViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit baa27d6

Please sign in to comment.