Skip to content

Commit

Permalink
ADD: better support for controlling the parallax and blur effects sep…
Browse files Browse the repository at this point in the history
…arately
  • Loading branch information
u10int committed Mar 29, 2014
1 parent 3385be3 commit bc6c01f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ Most of the customization options included within this component are related to

By default, parallax and blur effects are enabled. To disable one or both effects, just set the following properties on your instance:

self.parallaxEnabled = NO;
self.shouldBlurBackground = NO;

Note that currently if you disable the parallax effect, the background blur will also be disabled.
self.parallaxEnabled = NO; // default YES
self.shouldBlurBackground = NO; // default YES

By default, tapping on the image will not dismiss the focus view (as controlled by `shouldDismissOnTap`), but tapping outside of the image bounds will. You can change this by setting `shouldDismissOnImageTap` to `YES` on your `URBMediaFocusViewController` instance, which will allow tapping directly on the image to dismiss:

self.shouldDismissOnImageTap = YES;
self.shouldDismissOnImageTap = YES; // default NO

If you wish to only dismiss using UIDynamics, you can also dismiss the default tap gesture used to dismiss (not recommended for iOS 6 since UIDynamics isn't available):

self.shouldDismissOnTap = NO; // default YES

You can also provide copy and save actions for the presented photo from an action sheet when the image receives a long press gesture. By default this feature is disabled, so just control this using the `shouldShowPhotoActions` property:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ - (void)viewDidLoad {

self.mediaFocusController = [[URBMediaFocusViewController alloc] init];
self.mediaFocusController.delegate = self;
//self.mediaFocusController.shouldBlurBackground = NO; // uncomment if you don't want the background blurred
//self.mediaFocusController.parallaxEnabled = NO; // uncomment if you don't want the parallax (push-back) effect
//self.mediaFocusController.shouldDismissOnTap = NO; // uncomment if you wish to disable dismissing the view on a single tap outside image bounds
//self.mediaFocusController.shouldDismissOnImageTap = YES; // uncomment if you wish to support dismissing view on a single tap on the image itself

Expand Down
2 changes: 1 addition & 1 deletion URBMediaFocusViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
@property (nonatomic, assign) BOOL shouldBlurBackground;
@property (nonatomic, assign) BOOL parallaxEnabled;

// determines whether or not view should be dismissed when the container view is tapped anywhere, including outside image bounds
// determines whether or not view should be dismissed when the container view is tapped anywhere outside image bounds
@property (nonatomic, assign) BOOL shouldDismissOnTap;

// determines whether or not view should be dismissed when the container view is tapped within bounds of image view
Expand Down
21 changes: 15 additions & 6 deletions URBMediaFocusViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ - (void)showImage:(UIImage *)image fromRect:(CGRect)fromRect {
self.imageView.alpha = 0.2;

// create snapshot of background if parallax is enabled
if (self.parallaxEnabled) {
[self createViewsForParallax];
if (self.parallaxEnabled || self.shouldBlurBackground) {
[self createViewsForBackground];

// hide status bar, but store whether or not we need to unhide it later when dismissing this view
// NOTE: in iOS 7+, this only works if you set `UIViewControllerBasedStatusBarAppearance` to YES in your Info.plist
Expand Down Expand Up @@ -310,8 +310,10 @@ - (void)showImage:(UIImage *)image fromRect:(CGRect)fromRect {

if (self.snapshotView) {
self.blurredSnapshotView.alpha = 1.0f;
self.blurredSnapshotView.transform = CGAffineTransformScale(CGAffineTransformIdentity, __backgroundScale, __backgroundScale);
self.snapshotView.transform = CGAffineTransformScale(CGAffineTransformIdentity, __backgroundScale, __backgroundScale);
if (self.parallaxEnabled) {
self.blurredSnapshotView.transform = CGAffineTransformScale(CGAffineTransformIdentity, __backgroundScale, __backgroundScale);
self.snapshotView.transform = CGAffineTransformScale(CGAffineTransformIdentity, __backgroundScale, __backgroundScale);
}
}

} completion:^(BOOL finished) {
Expand Down Expand Up @@ -430,10 +432,17 @@ - (UIWindow *)keyWindow {
return [UIApplication sharedApplication].keyWindow;
}

- (void)createViewsForParallax {
- (void)createViewsForBackground {
// container view for window
CGRect containerFrame = CGRectMake(0, 0, CGRectGetWidth(self.keyWindow.frame), CGRectGetHeight(self.keyWindow.frame));

// inset container view so we can blur the edges, but we also need to scale up so when __backgroundScale is applied, everything lines up
CGRect containerFrame = CGRectMake(0, 0, CGRectGetWidth(self.keyWindow.frame) * (1.0f / __backgroundScale), CGRectGetHeight(self.keyWindow.frame) * (1.0f / __backgroundScale));
// only perform inset if `parallaxEnabled` is YES
if (self.parallaxEnabled) {
containerFrame.size.width *= 1.0f / __backgroundScale;
containerFrame.size.height *= 1.0f / __backgroundScale;
}

UIView *containerView = [[UIView alloc] initWithFrame:CGRectIntegral(containerFrame)];
containerView.backgroundColor = [UIColor blackColor];

Expand Down

0 comments on commit bc6c01f

Please sign in to comment.