Skip to content

Commit

Permalink
Merge branch 'release/0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaoj committed Jun 9, 2014
2 parents 2283406 + 44b60c7 commit 2991109
Show file tree
Hide file tree
Showing 64 changed files with 3,073 additions and 1,268 deletions.
9 changes: 5 additions & 4 deletions BSImagePicker.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "BSImagePicker"
s.version = "0.3"
s.version = "0.4"
s.summary = "BSImagePicker is a multiple image picker for iOS"
s.description = <<-DESC
A mix between the native iOS 7 gallery and facebooks image picker. Allows you to preview and select multiple images.
Expand All @@ -9,11 +9,12 @@ Pod::Spec.new do |s|
s.license = "MIT"
s.author = { "Joakim Gyllström" => "[email protected]" }
s.platform = :ios, "7.0"
s.source = { :git => "https://github.com/mikaoj/BSImagePicker.git", :tag => "0.3" }
s.source_files = "BSImagePicker/{Category,View,Model,Controller}/*.{h,m}"
s.exclude_files = "BSImagePicker/Controller/BSAppDelegate.{h,m}"
s.source = { :git => "https://github.com/mikaoj/BSImagePicker.git", :tag => "0.4" }
s.source_files = "BSImagePicker/**/*.{h,m}"
s.exclude_files = "BSImagePicker/Controller/BSAppDelegate.{h,m}", "BSImagePicker/Misc/main.m"
s.public_header_files = "BSImagePicker/Controller/BSImagePickerController.h", "BSImagePicker/Category/UIViewController+MultipleImagePicker.h"
s.requires_arc = true
s.frameworks = 'AssetsLibrary', 'UIKit'
s.screenshots = ["https://cloud.githubusercontent.com/assets/4034956/3030011/c7d86756-e03b-11e3-87b8-d682142967c2.png",
"https://cloud.githubusercontent.com/assets/4034956/3030009/c7d4c1b4-e03b-11e3-8cc7-bda50c85dd46.png",
"https://cloud.githubusercontent.com/assets/4034956/3030010/c7d6ddd2-e03b-11e3-8c50-03f92a99e47e.png",
Expand Down
280 changes: 228 additions & 52 deletions BSImagePicker.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#import <Foundation/Foundation.h>

@interface BSZoomInAnimator : NSObject <UIViewControllerAnimatedTransitioning>

@end
@end
89 changes: 89 additions & 0 deletions BSImagePicker/Animator/BSZoomInAnimator.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// The MIT License (MIT)
//
// Copyright (c) 2014 Joakim Gyllström
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#import "BSZoomInAnimator.h"
#import "BSPhotosController.h"
#import "BSPhotoCell.h"
#import "BSCollectionController+UICollectionView.h"
#import "UIImageViewModeScaleAspect.h"

@implementation BSZoomInAnimator

#pragma mark - UIViewControllerAnimatedTransitioning

- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext {
return 0.3;
}

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
BSPreviewController *toViewController = (BSPreviewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
BSPhotosController *fromViewController = (BSPhotosController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIView *containerView = [transitionContext containerView];

//Disable selection so we don't select a cell while the push animation is running
[fromViewController setDisableSelection:YES];

//Get cells
BSPhotoCell *fromCell = (BSPhotoCell *)[fromViewController.collectionView cellForItemAtIndexPath:toViewController.currentIndexPath];
BSPhotoCell *toCell = (BSPhotoCell *)[toViewController collectionView:toViewController.collectionView cellForItemAtIndexPath:toViewController.currentIndexPath];

//Setup views
[fromCell.imageView setHidden:YES];
[toViewController.view setHidden:YES];

//Setup scaling image
UIImageViewModeScaleAspect *scalingImage = [[UIImageViewModeScaleAspect alloc] initWithFrame:[containerView convertRect:fromCell.imageView.frame fromView:fromCell.imageView.superview]];
[scalingImage setContentMode:UIViewContentModeScaleAspectFill];
[scalingImage setImage:toCell.imageView.image];

//Init image scale
[scalingImage initToScaleAspectFitToFrame:CGRectMake(0, toViewController.collectionView.contentInset.top, toCell.imageView.frame.size.width, toCell.imageView.frame.size.height)];

//Add views to container view
[containerView addSubview:toViewController.view];
[containerView addSubview:scalingImage];

//Animate
[UIView animateWithDuration:[self transitionDuration:transitionContext]
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
[fromViewController.view setAlpha:0.0];
[scalingImage animaticToScaleAspectFit];
} completion:^(BOOL finished) {
//Finish image scaling and remove image view
[scalingImage animateFinishToScaleAspectFit];
[scalingImage removeFromSuperview];

//Unhide
[fromCell.imageView setHidden:NO];
[toViewController.view setHidden:NO];
[fromViewController.view setAlpha:1.0];

[transitionContext completeTransition:![transitionContext transitionWasCancelled]];

//Enable selection
[fromViewController setDisableSelection:NO];
}];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#import <Foundation/Foundation.h>

@interface BSZoomOutAnimator : NSObject <UIViewControllerAnimatedTransitioning>

@end
@end
96 changes: 96 additions & 0 deletions BSImagePicker/Animator/BSZoomOutAnimator.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// The MIT License (MIT)
//
// Copyright (c) 2014 Joakim Gyllström
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#import "BSZoomOutAnimator.h"
#import "BSPhotosController.h"
#import "BSPhotoCell.h"
#import "BSCollectionController+UICollectionView.h"
#import "UIImageViewModeScaleAspect.h"
#import "BSItemsModel.h"

@implementation BSZoomOutAnimator

- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext {
return 0.3;
}

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
BSPhotosController *toViewController = (BSPhotosController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
BSPreviewController *fromViewController = (BSPreviewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIView *containerView = [transitionContext containerView];

//Disable selection so we don't select a cell while the push animation is running
[fromViewController.collectionView setAllowsSelection:NO];

//Get cells
BSPhotoCell *fromCell = (BSPhotoCell *)[fromViewController.collectionView cellForItemAtIndexPath:fromViewController.currentIndexPath];
BSPhotoCell *toCell = (BSPhotoCell *)[toViewController.collectionView cellForItemAtIndexPath:fromViewController.currentIndexPath];

//Setup views
[toCell setHidden:YES];
[fromCell.imageView setHidden:YES];

UIImageView *iv = fromCell.imageView; // your image view
CGSize imageSize = iv.image.size;
CGFloat imageScale = fminf(CGRectGetWidth(iv.bounds)/imageSize.width, CGRectGetHeight(iv.bounds)/imageSize.height);
CGSize scaledImageSize = CGSizeMake(imageSize.width*imageScale, imageSize.height*imageScale);
CGRect imageFrame = CGRectMake(roundf(0.5f*(CGRectGetWidth(iv.bounds)-scaledImageSize.width)), roundf(0.5f*(CGRectGetHeight(iv.bounds)-scaledImageSize.height)), roundf(scaledImageSize.width), roundf(scaledImageSize.height));
CGRect scaledFrame = CGRectMake((fromCell.frame.size.width-imageFrame.size.width)/2.0, (fromCell.frame.size.height-imageFrame.size.height)/2.0, imageFrame.size.width, imageFrame.size.height);

//Setup scaling image
UIImageViewModeScaleAspect *scalingImage = [[UIImageViewModeScaleAspect alloc] initWithFrame:[containerView convertRect:scaledFrame fromView:fromCell.imageView.superview]];
[scalingImage setContentMode:UIViewContentModeScaleAspectFill];
[scalingImage setImage:fromCell.imageView.image];
[scalingImage setClipsToBounds:YES];

//Add views to container view
[containerView addSubview:toViewController.view];
[containerView addSubview:scalingImage];
[toViewController.view setAlpha:0.0];

//Init image scale
[scalingImage initToScaleAspectFillToFrame:CGRectMake(toCell.frame.origin.x, toCell.frame.origin.y+(toViewController.collectionView.contentInset.top-2.0), toCell.frame.size.width, toCell.frame.size.height)];

//Animate
[UIView animateWithDuration:[self transitionDuration:transitionContext]
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
[toViewController.view setAlpha:1.0];
[scalingImage animaticToScaleAspectFill];
} completion:^(BOOL finished) {
//Finish image scaling and remove image view
[scalingImage animateFinishToScaleAspectFill];
[scalingImage removeFromSuperview];

//Unhide
[fromCell.imageView setHidden:NO];
[toCell setHidden:NO];

[transitionContext completeTransition:![transitionContext transitionWasCancelled]];

//Enable selection
[fromViewController.collectionView setAllowsSelection:YES];
}];
}

@end
108 changes: 108 additions & 0 deletions BSImagePicker/Animator/UIImageViewModeScaleAspect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// UIImageViewModeScaleAspect.m
//
// http://www.viviencormier.fr/
//
// Created by Vivien Cormier on 02/05/13.
// Copyright (c) 2013 Vivien Cormier. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIImageViewModeScaleAspect : UIView

@property(nonatomic, strong) UIImage *image;

#pragma mark - Automatic Animate

/**
* Automatic Animate Fill to Fit
*
* @param frame
* @param duration
* @param delay
*/
- (void)animateToScaleAspectFitToFrame:(CGRect)frame
WithDuration:(float)duration
afterDelay:(float)delay;

/**
* Automatic Animate Fit to Fill
*
* @param frame
* @param duration
* @param delay
*/
- (void)animateToScaleAspectFillToFrame:(CGRect)frame
WithDuration:(float)duration
afterDelay:(float)delay;

/**
* Automatic Animate Fill to Fit with completion
*
* @param frame
* @param duration
* @param delay
* @param completion
*/
- (void)animateToScaleAspectFitToFrame:(CGRect)frame
WithDuration:(float)duration
afterDelay:(float)delay
completion:(void (^)(BOOL finished))completion;

/**
* Automatic Animate Fit to Fill with completion
*
* @param frame
* @param duration
* @param delay
* @param completion
*/
- (void)animateToScaleAspectFillToFrame:(CGRect)frame
WithDuration:(float)duration
afterDelay:(float)delay
completion:(void (^)(BOOL finished))completion;

#pragma mark - Manual Animate

#pragma mark - - Init Function

/**
* Init Manual Function Fit
*
* @param newFrame
*/
- (void)initToScaleAspectFitToFrame:(CGRect)newFrame;

/**
* Init Manual Function Fill
*
* @param newFrame
*/
- (void)initToScaleAspectFillToFrame:(CGRect)newFrame;

#pragma mark - - Animatic Function

/**
* Animatic Fucntion Fit
*/
- (void)animaticToScaleAspectFit;

/**
* Animatic Function Fill
*/
- (void)animaticToScaleAspectFill;

#pragma mark - - Last Function

/**
* Last Function Fit
*/
- (void)animateFinishToScaleAspectFit;

/**
* Last Function Fill
*/
- (void)animateFinishToScaleAspectFill;

@end
Loading

0 comments on commit 2991109

Please sign in to comment.