Skip to content

Commit

Permalink
Merge branch 'release/0.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaoj committed Oct 5, 2014
2 parents ba0608a + 77a9049 commit 7e139a0
Show file tree
Hide file tree
Showing 33 changed files with 275 additions and 751 deletions.
13 changes: 6 additions & 7 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.6.1"
s.version = "0.7"
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,15 +9,14 @@ 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.6.1" }
s.source = { :git => "https://github.com/mikaoj/BSImagePicker.git", :tag => "0.7" }
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.public_header_files = "BSImagePicker/Controller/BSImagePickerController.h", "BSImagePicker/Category/UIViewController+BSImagePicker.h"
s.requires_arc = true
s.frameworks = 'AssetsLibrary', 'UIKit', 'MediaPlayer'
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",
"https://cloud.githubusercontent.com/assets/4034956/3030008/c7915686-e03b-11e3-8e1f-cc8aa8680a6a.png"]
s.screenshots = ["https://cloud.githubusercontent.com/assets/4034956/4519853/de47afca-4ccd-11e4-9b6b-1a5aea5d9a69.png",
"https://cloud.githubusercontent.com/assets/4034956/4519855/de4df42a-4ccd-11e4-865c-4d2e8de6b135.png",
"https://cloud.githubusercontent.com/assets/4034956/4519854/de4a3c68-4ccd-11e4-8258-314ead7e959c.png"]
end

466 changes: 12 additions & 454 deletions BSImagePicker.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion BSImagePicker/Animator/BSShrinkAnimator.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionCo
[toViewController.view setAlpha:0.0];

//Init image scale
[scalingImage initToScaleAspectFillToFrame:CGRectMake(toCell.frame.origin.x, toCell.frame.origin.y+(fromViewController.navigationController.navigationBar.frame.origin.y + fromViewController.navigationController.navigationBar.frame.size.height), toCell.frame.size.width, toCell.frame.size.height)];
[scalingImage initToScaleAspectFillToFrame:[containerView convertRect:toCell.frame fromView:toCell.superview]];

//Animate
[UIView animateWithDuration:[self transitionDuration:transitionContext]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
@implementation BSCollectionController (BSItemsModel)

- (void)didUpdateModel:(id<BSItemsModel>)aModel {
[self.collectionView setContentOffset:CGPointMake(-self.collectionView.contentInset.left, -self.collectionView.contentInset.top)];
[self.collectionView reloadData];
}

@end
@end
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell

if([self.collectionModel isItemAtIndexPathSelected:indexPath]) {
[collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
[cell setSelected:YES animated:NO];

id selectedItem = [self.collectionModel itemAtIndexPath:indexPath];
NSInteger pictureNumber = [self.collectionModel.selectedItems indexOfObject:selectedItem]+1;
[cell setPictureNumber:pictureNumber selected:YES animated:NO];
} else {
[collectionView deselectItemAtIndexPath:indexPath animated:NO];
}

return cell;
Expand Down Expand Up @@ -71,20 +76,22 @@ - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndex
[self.collectionModel deselectItemAtIndexPath:indexPath];

BSPhotoCell *cell = (BSPhotoCell *)[collectionView cellForItemAtIndexPath:indexPath];
[cell setSelected:NO animated:YES];
[cell setPictureNumber:0 selected:NO animated:YES];

if([[BSImagePickerSettings sharedSetting] toggleBlock]) {
ALAsset *asset = [self.collectionModel itemAtIndexPath:indexPath];
[BSImagePickerSettings sharedSetting].toggleBlock(asset, NO);
}

[self.collectionView reloadItemsAtIndexPaths:self.collectionView.indexPathsForSelectedItems];
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
//Add item
[self.collectionModel selectItemAtIndexPath:indexPath];

BSPhotoCell *cell = (BSPhotoCell *)[collectionView cellForItemAtIndexPath:indexPath];
[cell setSelected:YES animated:YES];
[cell setPictureNumber:[self.collectionModel.selectedItems count] selected:YES animated:YES];

if([[BSImagePickerSettings sharedSetting] toggleBlock]) {
ALAsset *asset = [self.collectionModel itemAtIndexPath:indexPath];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ - (void)didUpdateModel:(id<BSItemsModel>)aModel {

ALAssetsGroup *assetsGroup = [[self.tableController.tableModel selectedItems] firstObject];

[self.albumButton setTitle:[assetsGroup valueForProperty:ALAssetsGroupPropertyName] forState:UIControlStateNormal];
[self updateAlbumTitle:[assetsGroup valueForProperty:ALAssetsGroupPropertyName]];

[self.collectionModel setupWithParentItem:assetsGroup];

[self hideAlbumView];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@

#import "BSPhotosController.h"

@protocol BSItemsModel;
@interface BSPhotosController (PrivateMethods)

- (void)finishButtonPressed:(id)sender;
- (void)albumButtonPressed:(id)sender;
- (void)showAlbumView;
- (void)hideAlbumView;
- (void)itemLongPressed:(UIGestureRecognizer *)recognizer;
- (void)syncSelectionInModel:(id<BSItemsModel>)aModel withCollectionView:(UICollectionView *)aCollectionView;
- (void)updateAlbumTitle:(NSString *)aTitle;
- (void)toggleDoneButton;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@

#import "BSPhotosController+PrivateMethods.h"
#import "BSImagePickerSettings.h"
#import "BSItemsModel.h"

@interface BSPhotosController (SuperPrivate)

- (void)updateDoneButtonWithSelectedAssets:(NSUInteger)selectedAssets;
- (void)setTitleWithoutAnimation:(NSString *)aTitle forButton:(UIButton *)aButton;
- (BOOL)isRightBarButton:(UIButton *)aButton;

@end

@implementation BSPhotosController (PrivateMethods)

Expand All @@ -38,14 +47,25 @@ - (void)finishButtonPressed:(id)sender {
[BSImagePickerSettings sharedSetting].finishBlock([self.collectionModel.selectedItems copy]);
}
}

//Remove selections if user doesn't want to keep them
if(![[BSImagePickerSettings sharedSetting] keepSelection]) {
[self.collectionModel clearSelection];
}
}

- (void)albumButtonPressed:(id)sender {
- (void)albumButtonPressed:(UIButton *)sender {
[UIView animateWithDuration:0.1
animations:^{
[sender setTransform:CGAffineTransformMakeScale(0.9, 0.9)];
}
completion:^(BOOL finished) {
[UIView animateWithDuration:0.1
animations:^{
[sender setTransform:CGAffineTransformMakeScale(1.0, 1.0)];
}
completion:nil];
}];
if([self.speechBubbleView isDescendantOfView:self.navigationController.view]) {
[self hideAlbumView];
} else {
Expand All @@ -58,68 +78,161 @@ - (void)albumButtonPressed:(id)sender {
- (void)showAlbumView {
[self.navigationController.view addSubview:self.coverView];
[self.navigationController.view addSubview:self.speechBubbleView];

CGFloat tableViewHeight = MIN(self.tableController.tableView.contentSize.height, 240);
CGRect frame = CGRectMake(0, 0, self.speechBubbleView.frame.size.width, tableViewHeight+7);

//Remember old values
CGFloat height = frame.size.height;
CGFloat width = frame.size.width;

//Set new frame
frame.size.height = 0.0;
frame.size.width = 0.0;
frame.origin.y = self.navigationController.navigationBar.frame.origin.y + self.navigationController.navigationBar.frame.size.height/2.0;
frame.origin.x = (self.view.frame.size.width - frame.size.width)/2.0;
[self.speechBubbleView setFrame:frame];

[UIView animateWithDuration:0.7
delay:0.0
usingSpringWithDamping:0.7
initialSpringVelocity:0
options:0
animations:^{
CGRect frame = self.speechBubbleView.frame;
frame.size.height = height;
frame.size.width = width;
frame.origin.y = self.navigationController.navigationBar.frame.origin.y + self.navigationController.navigationBar.frame.size.height;
frame.origin.x = (self.view.frame.size.width - frame.size.width)/2.0;
[self.speechBubbleView setFrame:frame];

[self.coverView setBackgroundColor:[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.5]];
} completion:nil];
CGRect frame = self.speechBubbleView.frame;
frame.size.height = height;
frame.size.width = width;
frame.origin.y = self.navigationController.navigationBar.frame.origin.y + self.navigationController.navigationBar.frame.size.height;
frame.origin.x = (self.view.frame.size.width - frame.size.width)/2.0;
[self.speechBubbleView setFrame:frame];

[self.coverView setBackgroundColor:[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.5]];
}
completion:nil];
}

- (void)hideAlbumView {
__block CGAffineTransform origTransForm = self.speechBubbleView.transform;

[UIView animateWithDuration:0.2
animations:^{
[self.speechBubbleView setTransform:CGAffineTransformConcat(CGAffineTransformMakeScale(0.1, 0.1), CGAffineTransformMakeTranslation(0, -(self.speechBubbleView.frame.size.height/2.0)))];
[self.coverView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0]];
} completion:^(BOOL finished) {
[self.speechBubbleView removeFromSuperview];
[self.speechBubbleView setTransform:origTransForm];
[self.coverView removeFromSuperview];
}];
[self.speechBubbleView setTransform:CGAffineTransformConcat(CGAffineTransformMakeScale(0.1, 0.1), CGAffineTransformMakeTranslation(0, -(self.speechBubbleView.frame.size.height/2.0)))];
[self.coverView setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0]];
}
completion:^(BOOL finished) {
[self.speechBubbleView removeFromSuperview];
[self.speechBubbleView setTransform:origTransForm];
[self.coverView removeFromSuperview];
}];
}

- (void)syncSelectionInModel:(id<BSItemsModel>)aModel withCollectionView:(UICollectionView *)aCollectionView {
[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
}

- (void)updateAlbumTitle:(NSString *)aTitle {
[UIView transitionWithView:self.albumButton
duration:0.4
options:UIViewAnimationOptionTransitionFlipFromBottom
animations:^{
[self.albumButton setTitle:aTitle
forState:UIControlStateNormal];
}
completion:nil];
}

- (void)toggleDoneButton {
if([self.collectionModel.selectedItems count] > 0) {
[self.navigationItem.rightBarButtonItem setEnabled:YES];
} else {
[self.navigationItem.rightBarButtonItem setEnabled:NO];
}

[self updateDoneButtonWithSelectedAssets:self.collectionModel.selectedItems.count];
}

#pragma mark - GestureRecognizer

- (void)itemLongPressed:(UIGestureRecognizer *)recognizer {
if(recognizer.state == UIGestureRecognizerStateBegan && ![[BSImagePickerSettings sharedSetting] previewDisabled]) {
[recognizer setEnabled:NO];

CGPoint location = [recognizer locationInView:self.collectionView];
NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:location];

[self.previewController setCollectionModel:self.collectionModel];
[self.previewController setCurrentIndexPath:indexPath];
[self.previewController.collectionView setContentInset:self.collectionView.contentInset];
[self.navigationController pushViewController:self.previewController animated:YES];

[recognizer setEnabled:YES];
}
}

@end

@implementation BSPhotosController (SuperPrivate)

#pragma mark - Private private

- (void)updateDoneButtonWithSelectedAssets:(NSUInteger)selectedAssets {
//This is not very future proof.
UIView *view = self.navigationController.navigationBar;
static NSString *origText;

for(UIView *subview in view.subviews) {
if([subview isKindOfClass:[NSClassFromString(@"UINavigationButton") class]]) {
//Second button is what we are looking for...
if([self isRightBarButton:(UIButton *)subview]) {
UIButton *hopeToBeDoneButton = (UIButton *)subview;

if(!origText) {
origText = [hopeToBeDoneButton titleForState:UIControlStateNormal];
}

if(selectedAssets > 0) {
[self setTitleWithoutAnimation:[NSString stringWithFormat:@"%@ (%d)", origText, selectedAssets] forButton:hopeToBeDoneButton];
} else {
[self setTitleWithoutAnimation:origText forButton:hopeToBeDoneButton];
}

break;
}
}
}
}

- (void)setTitleWithoutAnimation:(NSString *)aTitle forButton:(UIButton *)aButton {
BOOL wasEnabled = aButton.enabled;

[UIView setAnimationsEnabled:NO];
[aButton setEnabled:YES];
[aButton setTitle:aTitle forState:UIControlStateNormal];
[aButton setEnabled:wasEnabled];
[aButton layoutIfNeeded];
[UIView setAnimationsEnabled:YES];
}

- (BOOL)isRightBarButton:(UIButton *)aButton {
BOOL isRightBarButton = NO;

//Store previous values
BOOL wasRightEnabled = self.navigationItem.rightBarButtonItem.enabled;
BOOL wasButtonEnabled = aButton.enabled;

//Set a known state for both buttons
[aButton setEnabled:NO];
[self.navigationItem.rightBarButtonItem setEnabled:NO];

//Change one and see if other also changes
[self.navigationItem.rightBarButtonItem setEnabled:YES];
isRightBarButton = aButton.enabled == YES;

//Reset
[self.navigationItem.rightBarButtonItem setEnabled:wasRightEnabled];
[aButton setEnabled:wasButtonEnabled];

return isRightBarButton;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,20 @@

#import "BSPhotosController+UICollectionView.h"
#import "BSCollectionController+UICollectionView.h"
#import "BSPhotosController+PrivateMethods.h"

@implementation BSPhotosController (UICollectionView)

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
[super collectionView:collectionView didDeselectItemAtIndexPath:indexPath];

//Disable done button
if([self.collectionModel.selectedItems count] == 0) {
[self.navigationItem.rightBarButtonItem setEnabled:NO];
}

[self toggleDoneButton];
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[super collectionView:collectionView didSelectItemAtIndexPath:indexPath];

//Enable done button
if([self.collectionModel.selectedItems count] > 0) {
[self.navigationItem.rightBarButtonItem setEnabled:YES];
}

[self toggleDoneButton];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ @implementation BSPreviewController (UICollectionView)
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
[super collectionView:collectionView didDeselectItemAtIndexPath:indexPath];

[self.navigationItem setRightBarButtonItem:self.emptyItem animated:YES];
[self toggleCheckMarkForIndexPath:indexPath];
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[super collectionView:collectionView didSelectItemAtIndexPath:indexPath];

[self.navigationItem setRightBarButtonItem:self.checkMarkButton animated:YES];
[self toggleCheckMarkForIndexPath:indexPath];
}

@end
Loading

0 comments on commit 7e139a0

Please sign in to comment.