Skip to content

Commit

Permalink
Cleaning up code and project; README updated and new iOS7 screenshots…
Browse files Browse the repository at this point in the history
…; fixing some deprecated warnings; other small fixes
  • Loading branch information
Eduardo Callado committed Oct 3, 2013
1 parent 9923a84 commit 065100c
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 80 deletions.
4 changes: 2 additions & 2 deletions Classes/IDMCaptionView.m
Expand Up @@ -59,8 +59,8 @@ - (void)setupCaption {
_label.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
_label.opaque = NO;
_label.backgroundColor = [UIColor clearColor];
_label.textAlignment = UITextAlignmentCenter;
_label.lineBreakMode = UILineBreakModeWordWrap;
_label.textAlignment = NSTextAlignmentCenter;
_label.lineBreakMode = NSLineBreakByWordWrapping;
_label.numberOfLines = 3;
_label.textColor = [UIColor whiteColor];
_label.shadowColor = [UIColor colorWithWhite:0 alpha:0.5];
Expand Down
19 changes: 7 additions & 12 deletions Classes/IDMPhotoBrowser.h
Expand Up @@ -24,9 +24,9 @@
@protocol IDMPhotoBrowserDelegate <NSObject>
@optional
- (void)photoBrowser:(IDMPhotoBrowser *)photoBrowser didShowPhotoAtIndex:(NSUInteger)index;
- (void)photoBrowser:(IDMPhotoBrowser *)photoBrowser didDismissAtPageIndex:(NSUInteger)index;
- (void)photoBrowser:(IDMPhotoBrowser *)photoBrowser didDismissActionSheetWithButtonIndex:(NSUInteger)buttonIndex photoIndex:(NSUInteger)photoIndex;
- (IDMCaptionView *)photoBrowser:(IDMPhotoBrowser *)photoBrowser captionViewForPhotoAtIndex:(NSUInteger)index;
- (void)photoBrowser:(IDMPhotoBrowser *)photoBrowser didDismissAtPageIndex:(NSUInteger)index;
@end

// IDMPhotoBrowser
Expand All @@ -36,31 +36,27 @@
@property (nonatomic, strong) id <IDMPhotoBrowserDelegate> delegate;

// Toolbar customization
@property (nonatomic) BOOL displayDoneButton;
@property (nonatomic) BOOL displayToolbar;
@property (nonatomic) BOOL displayCounterLabel;
@property (nonatomic) BOOL displayActionButton;
@property (nonatomic, retain) NSArray *actionButtonTitles;
@property (nonatomic) BOOL displayArrowButton;
@property (nonatomic, retain) NSArray *actionButtonTitles;
@property (nonatomic, weak) UIImage *leftArrowImage, *leftArrowSelectedImage;
@property (nonatomic, weak) UIImage *rightArrowImage, *rightArrowSelectedImage;
@property (nonatomic, weak) UIColor *trackTintColor;
@property (nonatomic, weak) UIColor *tprogressTintColor;
@property (nonatomic, weak) UIImage *scaleImage;


// View customization
//@property (nonatomic) BOOL useWhiteBackgroundColor;
@property (nonatomic) BOOL displayDoneButton;
@property (nonatomic) BOOL useWhiteBackgroundColor;
@property (nonatomic, weak) UIImage *doneBackgroundImage;
//@property (nonatomic, weak) UIColor *trackTintColor, *progressTintColor;
@property (nonatomic, weak) UIImage *scaleImage;

//defines zooming of the background defauly 1.0
// defines zooming of the background defauly 1.0
@property (nonatomic) float backgroundScaleFactor;

//Animation time defult .28
// animation time defult .28
@property (nonatomic) float animationDuration;


// Init
- (id)initWithPhotos:(NSArray *)photosArray;

Expand All @@ -85,5 +81,4 @@
//Change Sender View
- (void)setSenderViewForAnimation:(UIView*)senderView;


@end
106 changes: 52 additions & 54 deletions Classes/IDMPhotoBrowser.m
Expand Up @@ -275,7 +275,7 @@ - (void)panGestureRecognized:(id)sender
{
if(scrollView.center.y > viewHalfHeight+40 || scrollView.center.y < viewHalfHeight-40) // Automatic Dismiss View
{
if (_senderViewForAnimation != nil && _currentPageIndex == _initalPageIndex) {
if (_senderViewForAnimation && _currentPageIndex == _initalPageIndex) {
[self performCloseAnimationWithScrollView:scrollView];
return;
}
Expand All @@ -295,7 +295,6 @@ - (void)panGestureRecognized:(id)sender
[UIView setAnimationDuration:animationDuration];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidFinish)];
[scrollView setCenter:CGPointMake(finalX, finalY)];
self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
//self.view.backgroundColor = [UIColor colorWithPatternImage:[self getImageFromView:backgroundImageView]];
Expand All @@ -319,7 +318,6 @@ - (void)panGestureRecognized:(id)sender
[UIView setAnimationDuration:animationDuration];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidFinish)];
[scrollView setCenter:CGPointMake(finalX, finalY)];
[UIView commitAnimations];
}
Expand Down Expand Up @@ -418,8 +416,7 @@ - (void)performAnimation
_senderViewForAnimation.hidden = YES;

[UIView animateWithDuration:_animationDuration animations:^{
CGAffineTransform zoom = CGAffineTransformScale(CGAffineTransformIdentity, _backgroundScaleFactor
, _backgroundScaleFactor);
CGAffineTransform zoom = CGAffineTransformScale(CGAffineTransformIdentity, _backgroundScaleFactor, _backgroundScaleFactor);
fadeView.backgroundColor = [UIColor blackColor];

[[[[UIApplication sharedApplication].delegate window] rootViewController].view setTransform:zoom];
Expand Down Expand Up @@ -474,7 +471,12 @@ - (void)performCloseAnimationWithScrollView:(IDMZoomingScrollView*)scrollView
[fadeView removeFromSuperview];
[resizableImageView removeFromSuperview];

[self doneButtonPressed:nil];
[self prepareForClosePhotoBrowser];

[self dismissViewControllerAnimated:NO completion:^{
UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
rootViewController.modalPresentationStyle = 0;
}];
}];
}

Expand Down Expand Up @@ -537,6 +539,32 @@ - (void)performLayout {
[self.view addGestureRecognizer:_panGesture];
}

- (void)prepareForClosePhotoBrowser
{
// Status Bar
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
//[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
} else {
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
}

if (self.wantsFullScreenLayout && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[[UIApplication sharedApplication] setStatusBarStyle:_previousStatusBarStyle animated:YES];
}

// Gesture
[[[[UIApplication sharedApplication] delegate] window] removeGestureRecognizer:_panGesture];

_autoHide = NO;

// Controls
[NSObject cancelPreviousPerformRequestsWithTarget:self]; // Cancel any pending toggles from taps
}

#pragma mark - View Lifecycle

- (void)viewDidLoad
Expand All @@ -548,8 +576,6 @@ - (void)viewDidLoad

/*if(!_senderViewForAnimation) // Default presentation (withoung animation)
{
//PB-TODO : test
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7")) // ios 7 or greater
[UIView animateWithDuration:0.0 animations:^{ } completion:^(BOOL finished) {
[UIView animateWithDuration:_animationDuration animations:^{ self.view.alpha = 1; }];
Expand Down Expand Up @@ -627,7 +653,7 @@ - (void)viewDidLoad

// Counter Label
_counterLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 95, 40)];
_counterLabel.textAlignment = UITextAlignmentCenter;
_counterLabel.textAlignment = NSTextAlignmentCenter;
_counterLabel.backgroundColor = [UIColor clearColor];
_counterLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];

Expand Down Expand Up @@ -686,19 +712,6 @@ - (void)viewWillAppear:(BOOL)animated {
[self hideControlsAfterDelay];
}

- (void)viewWillDisappear:(BOOL)animated {
// Controls
[NSObject cancelPreviousPerformRequestsWithTarget:self]; // Cancel any pending toggles from taps

// Status bar
if (self.wantsFullScreenLayout && UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[[UIApplication sharedApplication] setStatusBarStyle:_previousStatusBarStyle animated:animated];
}

// Super
[super viewWillDisappear:animated];
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
_viewIsActive = YES;
Expand Down Expand Up @@ -905,8 +918,8 @@ - (void)tilePages {
// Ignore padding as paging bounces encroach on that
// and lead to false page loads
CGRect visibleBounds = _pagingScrollView.bounds;
int iFirstIndex = (int)floorf((CGRectGetMinX(visibleBounds)+PADDING*2) / CGRectGetWidth(visibleBounds));
int iLastIndex = (int)floorf((CGRectGetMaxX(visibleBounds)-PADDING*2-1) / CGRectGetWidth(visibleBounds));
NSInteger iFirstIndex = (NSInteger) floorf((CGRectGetMinX(visibleBounds)+PADDING*2) / CGRectGetWidth(visibleBounds));
NSInteger iLastIndex = (NSInteger) floorf((CGRectGetMaxX(visibleBounds)-PADDING*2-1) / CGRectGetWidth(visibleBounds));
if (iFirstIndex < 0) iFirstIndex = 0;
if (iFirstIndex > [self numberOfPhotos] - 1) iFirstIndex = [self numberOfPhotos] - 1;
if (iLastIndex < 0) iLastIndex = 0;
Expand Down Expand Up @@ -1097,21 +1110,21 @@ - (CGRect)frameForCaptionView:(IDMCaptionView *)captionView atIndex:(NSUInteger)

#pragma mark - UIScrollView Delegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// Checks
if (!_viewIsActive || _performingLayout || _rotating) return;
// Tile pages
[self tilePages];
// Calculate current page
CGRect visibleBounds = _pagingScrollView.bounds;
int index = (int)(floorf(CGRectGetMidX(visibleBounds) / CGRectGetWidth(visibleBounds)));
if (!_viewIsActive || _performingLayout || _rotating) return;
// Tile pages
[self tilePages];
// Calculate current page
CGRect visibleBounds = _pagingScrollView.bounds;
NSInteger index = (NSInteger) (floorf(CGRectGetMidX(visibleBounds) / CGRectGetWidth(visibleBounds)));
if (index < 0) index = 0;
if (index > [self numberOfPhotos] - 1) index = [self numberOfPhotos] - 1;
NSUInteger previousCurrentPage = _currentPageIndex;
_currentPageIndex = index;
if (_currentPageIndex != previousCurrentPage) {
if (index > [self numberOfPhotos] - 1) index = [self numberOfPhotos] - 1;
NSUInteger previousCurrentPage = _currentPageIndex;
_currentPageIndex = index;
if (_currentPageIndex != previousCurrentPage) {
[self didStartViewingPageAtIndex:index];
}
}
Expand Down Expand Up @@ -1243,21 +1256,7 @@ - (void)setInitialPageIndex:(NSUInteger)index {

- (void)doneButtonPressed:(id)sender
{
// Status Bar
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
// iOS 7
//[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
} else {
// iOS 6
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
}

// Gesture
[[[[UIApplication sharedApplication] delegate] window] removeGestureRecognizer:_panGesture];

_autoHide = NO;
[self prepareForClosePhotoBrowser];

if (_senderViewForAnimation && _currentPageIndex == _initalPageIndex) {
IDMZoomingScrollView *scrollView = [self pageDisplayedAtIndex:_currentPageIndex];
Expand Down Expand Up @@ -1375,7 +1374,7 @@ - (void)actuallyEmailPhoto:(id<IDMPhoto>)photo {
}
}

#pragma mark Mail Compose Delegate
#pragma mark - Mail Compose Delegate

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
if (result == MFMailComposeResultFailed) {
Expand Down Expand Up @@ -1405,5 +1404,4 @@ - (void)showProgressHUDCompleteMessage:(NSString *)message {
}
}


@end
2 changes: 1 addition & 1 deletion Demo/PhotoBrowserDemo/Menu.m
Expand Up @@ -126,7 +126,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
int rows = 0;
NSInteger rows = 0;

if(section == 0)
rows = 1;
Expand Down
17 changes: 17 additions & 0 deletions IDMPhotoBrowser _1.2.6.podspec
@@ -0,0 +1,17 @@
Pod::Spec.new do |s|
s.name = "IDMPhotoBrowser"
s.summary = "Photo Browser / Viewer inspired by Facebook's and Tweetbot's with ARC support, swipe-to-dismiss, image progress and more."
s.version = "1.2.6"
s.homepage = "https://github.com/ideaismobile/IDMPhotoBrowser"
s.license = { :type => 'MIT', :file => 'LICENSE.txt' }
s.author = { "Appkraft" => "all@appkraft.net" }
s.source = { :git => "https://github.com/ideaismobile/IDMPhotoBrowser.git", :tag => "1.2.6" }
s.platform = :ios, '6.0'
s.source_files = 'Classes/*.{h,m}'
s.resources = 'Classes/IDMPhotoBrowser.bundle'
s.framework = 'MessageUI', 'QuartzCore', 'SystemConfiguration', 'MobileCoreServices'
s.requires_arc = true
s.dependency 'AFNetworking', '~> 1.3.1'
s.dependency 'DACircularProgress', '~> 2.1.0'
s.dependency 'SVProgressHUD', '~> 0.9'
end
41 changes: 30 additions & 11 deletions README.markdown
Expand Up @@ -56,19 +56,28 @@ First create a photos array containing IDMPhoto objects:
NSArray *photos = [IDMPhoto photosWithURLs:photosURL];
````
There are two main ways to presente the photoBrowser: With a fade on screen or with a zooming effect from an existing view.
There are two main ways to presente the photoBrowser, with a fade on screen or with a zooming effect from an existing view.
Presenting using a simple fade transition:
Using a simple fade transition:
``` objective-c
// Create and setup browser
IDMPhotoBrowser *browser = [[IDMPhotoBrowser alloc] initWithPhotos:photos];
```
Presenting from a view:
Zooming effect from a view:
``` objective-c
// Create and setup browser
IDMPhotoBrowser *browser = [[IDMPhotoBrowser alloc] initWithPhotos:photos animatedFromView:sender];
```
```
Presenting using a modal view controller:
``` objective-c
[self presentViewController:browser animated:YES completion:nil];
```
### Customization
##### Toolbar
You can customize the toolbar. There are three boolean properties you can set: displayActionButton (default is YES), displayArrowButton (default is YES) and displayCounterLabel (default is NO). If you dont want the toolbar at all, you can set displayToolbar = NO.
Expand All @@ -79,19 +88,29 @@ Toolbar setup example:
browser.displayCounterLabel = YES;
```
It is possible to use your own image on the toolbar arrows:
``` objective-c
browser.leftArrowImage = [UIImage imageNamed:@"IDMPhotoBrowser_customArrowLeft.png"];
browser.rightArrowImage = [UIImage imageNamed:@"IDMPhotoBrowser_customArrowRight.png"];
browser.leftArrowSelectedImage = [UIImage imageNamed:@"IDMPhotoBrowser_customArrowLeftSelected.png"];
browser.rightArrowSelectedImage = [UIImage imageNamed:@"IDMPhotoBrowser_customArrowRightSelected.png"];
```
If you want to use custom actions, set the actionButtonTitles array with the titles for the actionSheet. Then, implement the photoBrowser:didDismissActionSheetWithButtonIndex:photoIndex: method, from the IDMPhotoBrowser delegate
``` objective-c
browser.actionButtonTitles = @[@"Option 1", @"Option 2", @"Option 3", @"Option 4"];
```
Presenting using a modal view controller:
#### Others
``` objective-c
// Show
[self presentViewController:browser animated:YES completion:nil];
```
Others customizations you can make are: use white background color, don't display the done button and change the done button background image:
``` objective-c
browser.useWhiteBackgroundColor = YES;
browser.displayDoneButton = NO;
browser.doneBackgroundImage = [UIImage imageNamed:@"IDMPhotoBrowser_customDoneButton.png"];
```
### Photo Captions
Expand Down
Binary file modified Screenshots/idmphotobrowser_ss1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/idmphotobrowser_ss2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/idmphotobrowser_ss3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/idmphotobrowser_ss4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/idmphotobrowser_ss5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/idmphotobrowser_thumb1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/idmphotobrowser_thumb2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/idmphotobrowser_thumb3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/idmphotobrowser_thumb4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshots/idmphotobrowser_thumb5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 065100c

Please sign in to comment.