diff --git a/Classes/KIImagePager.h b/Classes/KIImagePager.h new file mode 100644 index 0000000..d50a946 --- /dev/null +++ b/Classes/KIImagePager.h @@ -0,0 +1,61 @@ +// +// KIImagePager.h +// KIImagePager +// +// Created by Marcus Kida on 07.04.13. +// Copyright (c) 2013 Marcus Kida. All rights reserved. +// + +#import +#import + +@class KIImagePager; + +@protocol KIImagePagerDataSource + +@required +- (NSArray *) arrayWithImages; +- (UIViewContentMode) contentModeForImage:(NSUInteger)image; + +@optional +- (UIImage *) placeHolderImageForImagePager; +- (NSString *) captionForImageAtIndex:(NSUInteger)index; + +@end + +@protocol KIImagePagerDelegate + +@optional +- (void) imagePager:(KIImagePager *)imagePager didScrollToIndex:(NSUInteger)index; +- (void) imagePager:(KIImagePager *)imagePager didSelectImageAtIndex:(NSUInteger)index; + +@end + +@interface KIImagePager : UIView + +// Delegate and Datasource +@property (weak) IBOutlet id dataSource; +@property (weak) IBOutlet id delegate; + +// General +@property (assign) UIViewContentMode contentMode; +@property (nonatomic, retain) UIPageControl *pageControl; +@property (nonatomic, assign) NSUInteger currentPage; +@property (nonatomic, assign) BOOL indicatorDisabled; +@property (nonatomic, assign) BOOL hidePageControlForSinglePages; // Defaults YES + +// Slideshow +@property (assign) NSUInteger slideshowTimeInterval; // Defaults 0.0f (off) +@property (assign) BOOL slideshowShouldCallScrollToDelegate; // Defaults YES + +// Caption Label +@property (nonatomic, strong) UIColor *captionTextColor; // Defaults Black +@property (nonatomic, strong) UIColor *captionBackgroundColor; // Defaults White (with an alpha of .7f) +@property (nonatomic, strong) UIFont *captionFont; // Defaults to Helvetica 12.0f points + +- (void) reloadData; +- (void) setCurrentPage:(NSUInteger)currentPage animated:(BOOL)animated; +- (void) updateCaptionLabelForImageAtIndex:(NSUInteger)index; + +@end + diff --git a/Classes/KIImagePager.m b/Classes/KIImagePager.m new file mode 100644 index 0000000..f0f6004 --- /dev/null +++ b/Classes/KIImagePager.m @@ -0,0 +1,378 @@ +// +// KIImagePager.m +// KIImagePager +// +// Created by Marcus Kida on 07.04.13. +// Copyright (c) 2013 Marcus Kida. All rights reserved. +// + +#define kPageControlHeight 30 +#define kOverlayWidth 50 +#define kOverlayHeight 15 + +#import "KIImagePager.h" + +@interface KIImagePager () +{ + __weak id _dataSource; + __weak id _delegate; + + UIScrollView *_scrollView; + UIPageControl *_pageControl; + UILabel *_countLabel; + UILabel *_captionLabel; + UIView *_indicatorBackground; + NSTimer *_slideshowTimer; + NSUInteger _slideshowTimeInterval; + NSMutableDictionary *_activityIndicators; + + BOOL _indicatorDisabled; +} +@end + +@implementation KIImagePager + +@synthesize dataSource = _dataSource; +@synthesize delegate = _delegate; +@synthesize contentMode = _contentMode; +@synthesize pageControl = _pageControl; +@synthesize indicatorDisabled = _indicatorDisabled; + +- (id)initWithFrame:(CGRect)frame +{ + if ((self = [super initWithFrame:frame])) { + // Initialization code + [self initialize]; + } + return self; +} + +- (id)initWithCoder:(NSCoder *)aDecoder +{ + if ((self = [super initWithCoder:aDecoder])) { + // Initialization code + } + return self; +} + +- (void) awakeFromNib +{ + [super awakeFromNib]; +} + +- (void) layoutSubviews +{ + [self initialize]; +} + +#pragma mark - General +- (void) initialize +{ + self.clipsToBounds = YES; + self.slideshowShouldCallScrollToDelegate = YES; + self.captionBackgroundColor = [UIColor whiteColor]; + self.captionTextColor = [UIColor blackColor]; + self.captionFont = [UIFont fontWithName:@"Helvetica-Light" size:12.0f]; + self.hidePageControlForSinglePages = YES; + + [self initializeScrollView]; + [self initializePageControl]; + if(!_indicatorDisabled) { + [self initalizeImageCounter]; + } + [self initializeCaption]; + [self loadData]; +} + +- (UIColor *) randomColor +{ + return [UIColor colorWithHue:(arc4random() % 256 / 256.0) + saturation:(arc4random() % 128 / 256.0) + 0.5 + brightness:(arc4random() % 128 / 256.0) + 0.5 + alpha:1]; +} + +- (void) initalizeImageCounter +{ + _indicatorBackground = [[UIView alloc] initWithFrame:CGRectMake(_scrollView.frame.size.width-(kOverlayWidth-4), + _scrollView.frame.size.height-kOverlayHeight, + kOverlayWidth, + kOverlayHeight)]; + _indicatorBackground.backgroundColor = [UIColor whiteColor]; + _indicatorBackground.alpha = 0.7f; + _indicatorBackground.layer.cornerRadius = 5.0f; + + UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 18, 18)]; + [icon setImage:[UIImage imageNamed:@"KICamera"]]; + icon.center = CGPointMake(_indicatorBackground.frame.size.width-18, _indicatorBackground.frame.size.height/2); + [_indicatorBackground addSubview:icon]; + + _countLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 48, 24)]; + [_countLabel setTextAlignment:NSTextAlignmentCenter]; + [_countLabel setBackgroundColor:[UIColor clearColor]]; + [_countLabel setTextColor:[UIColor blackColor]]; + [_countLabel setFont:[UIFont systemFontOfSize:11.0f]]; + _countLabel.center = CGPointMake(15, _indicatorBackground.frame.size.height/2); + [_indicatorBackground addSubview:_countLabel]; + + [self addSubview:_indicatorBackground]; +} + +- (void) initializeCaption +{ + _captionLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 170, _scrollView.frame.size.width - 10, 20)]; + [_captionLabel setBackgroundColor:self.captionBackgroundColor]; + [_captionLabel setTextColor:self.captionTextColor]; + [_captionLabel setFont:self.captionFont]; + + _captionLabel.alpha = 0.7f; + _captionLabel.layer.cornerRadius = 5.0f; + + [self addSubview:_captionLabel]; +} + +- (void) reloadData +{ + for (UIView *view in _scrollView.subviews) + [view removeFromSuperview]; + + [self loadData]; + [self checkWetherToToggleSlideshowTimer]; +} + +#pragma mark - ScrollView Initialization +- (void) initializeScrollView +{ + _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; + _scrollView.delegate = self; + _scrollView.pagingEnabled = YES; + _scrollView.showsHorizontalScrollIndicator = NO; + _scrollView.showsVerticalScrollIndicator = NO; + _scrollView.autoresizingMask = self.autoresizingMask; + [self addSubview:_scrollView]; +} + +- (void) loadData +{ + NSArray *aImageUrls = (NSArray *)[_dataSource arrayWithImages]; + _activityIndicators = [NSMutableDictionary new]; + + [self updateCaptionLabelForImageAtIndex:0]; + + if([aImageUrls count] > 0) { + [_scrollView setContentSize:CGSizeMake(_scrollView.frame.size.width * [aImageUrls count], + _scrollView.frame.size.height)]; + + for (int i = 0; i < [aImageUrls count]; i++) { + CGRect imageFrame = CGRectMake(_scrollView.frame.size.width * i, 0, _scrollView.frame.size.width, _scrollView.frame.size.height); + UIImageView *imageView = [[UIImageView alloc] initWithFrame:imageFrame]; + [imageView setBackgroundColor:[UIColor clearColor]]; + //[imageView setContentMode:[_dataSource contentModeForImage:i]]; + [imageView setTag:i]; + + if([[aImageUrls objectAtIndex:i] isKindOfClass:[UIImage class]]) { + // Set ImageView's Image directly + [imageView setImage:(UIImage *)[aImageUrls objectAtIndex:i]]; + } else if([[aImageUrls objectAtIndex:i] isKindOfClass:[NSString class]] || + [[aImageUrls objectAtIndex:i] isKindOfClass:[NSURL class]]) { + // Instantiate and show Actvity Indicator + UIActivityIndicatorView *activityIndicator = [UIActivityIndicatorView new]; + activityIndicator.center = (CGPoint){_scrollView.frame.size.width/2, _scrollView.frame.size.height/2}; + activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite; + [imageView addSubview:activityIndicator]; + [activityIndicator startAnimating]; + [_activityIndicators setObject:activityIndicator forKey:[NSString stringWithFormat:@"%d", i]]; + + // Asynchronously retrieve image + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ + NSData *imageData = [NSData dataWithContentsOfURL: + [[aImageUrls objectAtIndex:i] isKindOfClass:[NSURL class]]? + [aImageUrls objectAtIndex:i]: + [NSURL URLWithString:(NSString *)[aImageUrls objectAtIndex:i]]]; + dispatch_sync(dispatch_get_main_queue(), ^{ + [imageView setImage:[UIImage imageWithData:imageData]]; + + // Stop and Remove Activity Indicator + UIActivityIndicatorView *indicatorView = (UIActivityIndicatorView *)[_activityIndicators objectForKey:[NSString stringWithFormat:@"%d", i]]; + if (indicatorView) { + [indicatorView stopAnimating]; + [_activityIndicators removeObjectForKey:[NSString stringWithFormat:@"%d", i]]; + } + }); + }); + } + + // Add GestureRecognizer to ImageView + UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc] + initWithTarget:self + action:@selector(imageTapped:)]; + [singleTapGestureRecognizer setNumberOfTapsRequired:1]; + [imageView addGestureRecognizer:singleTapGestureRecognizer]; + [imageView setUserInteractionEnabled:YES]; + + [_scrollView addSubview:imageView]; + } + + [_countLabel setText:[NSString stringWithFormat:@"%d", [[_dataSource arrayWithImages] count]]]; + _pageControl.numberOfPages = [(NSArray *)[_dataSource arrayWithImages] count]; + } else { + UIImageView *blankImage = [[UIImageView alloc] initWithFrame:_scrollView.frame]; + [blankImage setImage:[_dataSource placeHolderImageForImagePager]]; + [_scrollView addSubview:blankImage]; + } +} + +- (void) imageTapped:(UITapGestureRecognizer *)sender +{ + if([_delegate respondsToSelector:@selector(imagePager:didSelectImageAtIndex:)]) { + [_delegate imagePager:self didSelectImageAtIndex:[(UIGestureRecognizer *)sender view].tag]; + } +} + +- (void) setIndicatorDisabled:(BOOL)indicatorDisabled +{ + if(indicatorDisabled) { + [_pageControl removeFromSuperview]; + [_indicatorBackground removeFromSuperview]; + } else { + [self addSubview:_pageControl]; + [self addSubview:_indicatorBackground]; + } + + _indicatorDisabled = indicatorDisabled; +} + +#pragma mark - PageControl Initialization +- (void) initializePageControl +{ + CGRect pageControlFrame = CGRectMake(0, 0, _scrollView.frame.size.width, kPageControlHeight); + _pageControl = [[UIPageControl alloc] initWithFrame:pageControlFrame]; + //in default library it's not 115 but 12 + _pageControl.center = CGPointMake(_scrollView.frame.size.width/2, _scrollView.frame.size.height - 115); + _pageControl.userInteractionEnabled = NO; + [self addSubview:_pageControl]; +} + +#pragma mark - ScrollView Delegate; +- (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView +{ + int currentPage = lround((float)scrollView.contentOffset.x / scrollView.frame.size.width); + _pageControl.currentPage = currentPage; + + [self updateCaptionLabelForImageAtIndex:currentPage]; + [self fireDidScrollToIndexDelegateForPage:currentPage]; +} + +#pragma mark - Delegate Helper +- (void) updateCaptionLabelForImageAtIndex:(NSUInteger)index +{ + if ([_dataSource respondsToSelector:@selector(captionForImageAtIndex:)]) { + if ([[_dataSource captionForImageAtIndex:index] length] > 0) { + [_captionLabel setHidden:NO]; + [_captionLabel setText:[NSString stringWithFormat:@" %@", [_dataSource captionForImageAtIndex:index]]]; + NSLog(@"Caption vaut: %@", [NSString stringWithFormat:@" %@", [_dataSource captionForImageAtIndex:index]]); + return; + } + } + [_captionLabel setHidden:YES]; +} + +- (void) fireDidScrollToIndexDelegateForPage:(NSUInteger)page +{ + if([_delegate respondsToSelector:@selector(imagePager:didScrollToIndex:)]) { + [_delegate imagePager:self didScrollToIndex:page]; + } +} + +#pragma mark - Slideshow +- (void) slideshowTick:(NSTimer *)timer +{ + NSUInteger nextPage = 0; + if([_pageControl currentPage] < ([[_dataSource arrayWithImages] count] - 1)) { + nextPage = [_pageControl currentPage] + 1; + } + + [_scrollView scrollRectToVisible:CGRectMake(self.frame.size.width * nextPage, 0, self.frame.size.width, self.frame.size.width) animated:YES]; + [_pageControl setCurrentPage:nextPage]; + + [self updateCaptionLabelForImageAtIndex:nextPage]; + + if (self.slideshowShouldCallScrollToDelegate) { + [self fireDidScrollToIndexDelegateForPage:nextPage]; + } +} + +- (void) checkWetherToToggleSlideshowTimer +{ + if (_slideshowTimeInterval > 0) { + if ([(NSArray *)[_dataSource arrayWithImages] count] > 1) { + _slideshowTimer = [NSTimer scheduledTimerWithTimeInterval:_slideshowTimeInterval target:self selector:@selector(slideshowTick:) userInfo:nil repeats:YES]; + } + } +} + +#pragma mark - Setter / Getter +- (void) setSlideshowTimeInterval:(NSUInteger)slideshowTimeInterval +{ + _slideshowTimeInterval = slideshowTimeInterval; + + if([_slideshowTimer isValid]) { + [_slideshowTimer invalidate]; + } + [self checkWetherToToggleSlideshowTimer]; +} + +- (NSUInteger) slideshowTimeInterval +{ + return _slideshowTimeInterval; +} + +- (void) setCaptionBackgroundColor:(UIColor *)captionBackgroundColor +{ + [_captionLabel setBackgroundColor:captionBackgroundColor]; + _captionBackgroundColor = captionBackgroundColor; +} + +- (void) setCaptionTextColor:(UIColor *)captionTextColor +{ + [_captionLabel setTextColor:captionTextColor]; + _captionTextColor = captionTextColor; +} + +- (void) setCaptionFont:(UIFont *)captionFont +{ + [_captionLabel setFont:captionFont]; + _captionFont = captionFont; +} + +- (void) setHidePageControlForSinglePages:(BOOL)hidePageControlForSinglePages +{ + _hidePageControlForSinglePages = hidePageControlForSinglePages; + if (hidePageControlForSinglePages) { + if ([(NSArray *)[_dataSource arrayWithImages] count] < 2) { + [_pageControl setHidden:YES]; + return; + } + } + [_pageControl setHidden:NO]; +} + +- (NSUInteger) currentPage +{ + return [_pageControl currentPage]; +} + +- (void) setCurrentPage:(NSUInteger)currentPage +{ + [self setCurrentPage:currentPage animated:YES]; +} + +- (void) setCurrentPage:(NSUInteger)currentPage animated:(BOOL)animated +{ + NSAssert((currentPage < [(NSArray *)[_dataSource arrayWithImages] count]), @"currentPage must not exceed maximum number of images"); + + [_pageControl setCurrentPage:currentPage]; + [_scrollView scrollRectToVisible:CGRectMake(self.frame.size.width * currentPage, 0, self.frame.size.width, self.frame.size.width) animated:animated]; +} + +@end diff --git a/Classes/TGFoursquareLocationDetail.h b/Classes/TGFoursquareLocationDetail.h new file mode 100644 index 0000000..9347250 --- /dev/null +++ b/Classes/TGFoursquareLocationDetail.h @@ -0,0 +1,61 @@ +// +// TGFoursquareLocationDetail.h +// TGFoursquareLocationDetail-Demo +// +// Created by Thibault Guégan on 15/12/2013. +// Copyright (c) 2013 Thibault Guégan. All rights reserved. +// + +#import +#import "KIImagePager.h" + +@protocol TGFoursquareLocationDetailDelegate; + +@interface TGFoursquareLocationDetail : UIView + +@property (nonatomic) CGFloat defaultimagePagerHeight; + +/** + How fast is the table view scrolling with the image picker +*/ +@property (nonatomic) CGFloat parallaxScrollFactor; + +@property (nonatomic) CGFloat headerFade; + +@property (nonatomic, strong) KIImagePager *imagePager; + +@property (nonatomic) int nbImages; + +@property (nonatomic) int currentImage; + +@property (nonatomic) CGRect defaultimagePagerFrame; + +@property (nonatomic, strong) UITableView *tableView; + +@property (nonatomic, strong) UIView *backgroundView; + +@property (nonatomic, strong) UIColor *backgroundViewColor; + +@property (nonatomic, strong) UIView *headerView; + +@property (nonatomic, weak) id tableViewDataSource; + +@property (nonatomic, weak) id tableViewDelegate; + +@property (nonatomic, weak) id delegate; + +@end + +@protocol TGFoursquareLocationDetailDelegate + +@optional + +- (void)locationDetail:(TGFoursquareLocationDetail *)locationDetail + imagePagerDidLoad:(KIImagePager *)imagePager; + +- (void)locationDetail:(TGFoursquareLocationDetail *)locationDetail + tableViewDidLoad:(UITableView *)tableView; + +- (void)locationDetail:(TGFoursquareLocationDetail *)locationDetail + headerViewDidLoad:(UIView *)headerView; +@end diff --git a/Classes/TGFoursquareLocationDetail.m b/Classes/TGFoursquareLocationDetail.m new file mode 100644 index 0000000..d3ea1c4 --- /dev/null +++ b/Classes/TGFoursquareLocationDetail.m @@ -0,0 +1,257 @@ +// +// TGFoursquareLocationDetail.m +// TGFoursquareLocationDetail-Demo +// +// Created by Thibault Guégan on 15/12/2013. +// Copyright (c) 2013 Thibault Guégan. All rights reserved. +// + +#import "TGFoursquareLocationDetail.h" + +@implementation TGFoursquareLocationDetail + +- (id)init +{ + self = [super init]; + if (self) { + [self initialize]; + } + return self; +} + +- (id)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + [self initialize]; + } + return self; +} + +- (id)initWithCoder:(NSCoder *)aDecoder +{ + self = [super initWithCoder:aDecoder]; + if (self) { + [self initialize]; + } + return self; +} + +- (void)initialize +{ + _defaultimagePagerHeight = 180.0f; + _parallaxScrollFactor = 0.6f; + _headerFade = 130.0f; + self.autoresizesSubviews = YES; + self.autoresizingMask = UIViewAutoresizingFlexibleWidth | + UIViewAutoresizingFlexibleHeight; + self.backgroundViewColor = [UIColor clearColor]; +} + +- (void)dealloc +{ + [self.tableView removeObserver:self forKeyPath:@"contentOffset"]; +} + +- (void)layoutSubviews +{ + [super layoutSubviews]; + + + if (!self.tableView) { + _tableView = [[UITableView alloc] initWithFrame:self.bounds]; + self.tableView.backgroundColor = [UIColor clearColor]; + self.tableView.delegate = self.tableViewDelegate; + self.tableView.dataSource = self.tableViewDataSource; + self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | + UIViewAutoresizingFlexibleHeight; + + // Add scroll view KVO + void *context = (__bridge void *)self; + [self.tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:context]; + + [self addSubview:self.tableView]; + + if([self.delegate respondsToSelector:@selector(locationDetail:tableViewDidLoad:)]){ + [self.delegate locationDetail:self tableViewDidLoad:self.tableView]; + } + + } + + if (!self.tableView.tableHeaderView) { + CGRect tableHeaderViewFrame = CGRectMake(0.0, 0.0, self.tableView.frame.size.width, self.defaultimagePagerHeight); + UIView *tableHeaderView = [[UIView alloc] initWithFrame:tableHeaderViewFrame]; + tableHeaderView.backgroundColor = [UIColor clearColor]; + self.tableView.tableHeaderView = tableHeaderView; + + UISwipeGestureRecognizer *swipeGestureRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(catchHeaderGestureRight:)]; + swipeGestureRight.direction = UISwipeGestureRecognizerDirectionRight ; + swipeGestureRight.cancelsTouchesInView = YES; + + UISwipeGestureRecognizer *swipeGestureLeft = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(catchHeaderGestureLeft:)]; + swipeGestureLeft.direction = UISwipeGestureRecognizerDirectionLeft ; + swipeGestureLeft.cancelsTouchesInView = YES; + + UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(catchTapEvent:)]; + + [self.tableView.tableHeaderView addGestureRecognizer:swipeGestureRight]; + [self.tableView.tableHeaderView addGestureRecognizer:swipeGestureLeft]; + [self.tableView.tableHeaderView addGestureRecognizer:tapRecognizer]; + } + + if(!self.imagePager){ + self.defaultimagePagerFrame = CGRectMake(0.0f, -self.defaultimagePagerHeight * self.parallaxScrollFactor *2, self.tableView.frame.size.width, self.defaultimagePagerHeight + (self.defaultimagePagerHeight * self.parallaxScrollFactor * 4)); + _imagePager = [[KIImagePager alloc] initWithFrame:self.defaultimagePagerFrame]; + self.imagePager.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + + + self.imagePager.indicatorDisabled = YES; + + [self insertSubview:self.imagePager belowSubview:self.tableView]; + + if([self.delegate respondsToSelector:@selector(locationDetail:imagePagerDidLoad:)]){ + [self.delegate locationDetail:self imagePagerDidLoad:self.imagePager]; + } + } + + // Add the background tableView + if (!self.backgroundView) { + + UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, self.defaultimagePagerHeight, + self.tableView.frame.size.width, + self.tableView.frame.size.height - self.defaultimagePagerHeight)]; + view.backgroundColor = self.backgroundViewColor; + self.backgroundView = view; + self.backgroundView.userInteractionEnabled=NO; + [self.tableView insertSubview:self.backgroundView atIndex:0]; + } + +} + +-(void)catchHeaderGestureRight:(UISwipeGestureRecognizer*)sender +{ + NSLog(@"header gesture right"); + + if(self.currentImage > 0){ + self.currentImage --; + [self.imagePager setCurrentPage:self.currentImage animated:YES]; + + [self.imagePager.delegate imagePager:self.imagePager didScrollToIndex:self.currentImage]; + [self.imagePager updateCaptionLabelForImageAtIndex:self.currentImage]; + } +} + +-(void)catchHeaderGestureLeft:(UISwipeGestureRecognizer*)sender +{ + NSLog(@"header gesture Left"); + + if(self.currentImage < [[self.imagePager.dataSource arrayWithImages] count] -1){ + self.currentImage ++; + [self.imagePager setCurrentPage:self.currentImage animated:YES]; + + [self.imagePager.delegate imagePager:self.imagePager didScrollToIndex:self.currentImage]; + [self.imagePager updateCaptionLabelForImageAtIndex:self.currentImage]; + } +} + +-(void)catchTapEvent:(UITapGestureRecognizer*)sender +{ + NSLog(@"tap gesture"); + + [self.imagePager.delegate imagePager:self.imagePager didSelectImageAtIndex:self.currentImage]; +} + +- (void)setTableViewDataSource:(id)tableViewDataSource +{ + _tableViewDataSource = tableViewDataSource; + self.tableView.dataSource = _tableViewDataSource; + + if (_tableViewDelegate) { + [self.tableView reloadData]; + } +} + +- (void)setTableViewDelegate:(id)tableViewDelegate +{ + _tableViewDelegate = tableViewDelegate; + self.tableView.delegate = _tableViewDelegate; + + if (_tableViewDataSource) { + [self.tableView reloadData]; + } +} + +- (void)setHeaderView:(UIView *)headerView +{ + _headerView = headerView; + + if([self.delegate respondsToSelector:@selector(locationDetail:headerViewDidLoad:)]){ + [self.delegate locationDetail:self headerViewDidLoad:self.headerView]; + } +} + +#pragma mark - KVO Methods + +- (void)observeValueForKeyPath:(NSString *)keyPath + ofObject:(id)object + change:(NSDictionary *)change + context:(void *)context +{ + // Make sure we are observing this value. + if (context != (__bridge void *)self) { + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; + return; + } + + if ((object == self.tableView) && + ([keyPath isEqualToString:@"contentOffset"] == YES)) { + [self scrollViewDidScrollWithOffset:self.tableView.contentOffset.y]; + return; + } +} + +- (void)scrollViewDidScrollWithOffset:(CGFloat)scrollOffset +{ + CGFloat junkViewFrameYAdjustment = 0.0; + + // If the user is pulling down + if (scrollOffset < 0) { + junkViewFrameYAdjustment = self.defaultimagePagerFrame.origin.y - (scrollOffset * self.parallaxScrollFactor); + } + + // If the user is scrolling normally, + else { + junkViewFrameYAdjustment = self.defaultimagePagerFrame.origin.y - (scrollOffset * self.parallaxScrollFactor); + + // Don't move the map way off-screen + if (junkViewFrameYAdjustment <= -(self.defaultimagePagerFrame.size.height)) { + junkViewFrameYAdjustment = -(self.defaultimagePagerFrame.size.height); + } + + } + + //NSLog(@"scrollOffset: %f",scrollOffset); + + if(scrollOffset > _headerFade && _headerView.alpha == 0.0){ //make the header appear + _headerView.alpha = 0; + _headerView.hidden = NO; + [UIView animateWithDuration:0.3 animations:^{ + _headerView.alpha = 1; + }]; + } + else if(scrollOffset < _headerFade && _headerView.alpha == 1.0){ //make the header disappear + [UIView animateWithDuration:0.3 animations:^{ + _headerView.alpha = 0; + } completion: ^(BOOL finished) { + _headerView.hidden = YES; + }]; + } + + if (junkViewFrameYAdjustment) { + CGRect newJunkViewFrame = self.imagePager.frame; + newJunkViewFrame.origin.y = junkViewFrameYAdjustment; + self.imagePager.frame = newJunkViewFrame; + } +} + +@end diff --git a/TGFoursquareLocationDetail-Demo.xcodeproj/project.xcworkspace/xcuserdata/thibaultguegan.xcuserdatad/UserInterfaceState.xcuserstate b/TGFoursquareLocationDetail-Demo.xcodeproj/project.xcworkspace/xcuserdata/thibaultguegan.xcuserdatad/UserInterfaceState.xcuserstate index 6d28d8d..12ab08c 100644 Binary files a/TGFoursquareLocationDetail-Demo.xcodeproj/project.xcworkspace/xcuserdata/thibaultguegan.xcuserdatad/UserInterfaceState.xcuserstate and b/TGFoursquareLocationDetail-Demo.xcodeproj/project.xcworkspace/xcuserdata/thibaultguegan.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/TGFoursquareLocationDetail.podspec b/TGFoursquareLocationDetail.podspec new file mode 100644 index 0000000..54cdb13 --- /dev/null +++ b/TGFoursquareLocationDetail.podspec @@ -0,0 +1,23 @@ +Pod::Spec.new do |s| + + s.name = 'TGFoursquareLocationDetail' + s.version = '1.0.0' + s.summary = 'iOS project recreating Foursquare design and behaviour when presenting location details' + s.homepage = 'https://github.com/Tibolte/TGFoursquareLocationDetail-Demo' + s.license = { + :type => 'MIT', + :file => 'LICENSE' + } + s.author = { + 'Thibault Guégan' => 'thibault.guegan@gmail.com' + } + s.source = { + :git => 'https://github.com/Tibolte/TGFoursquareLocationDetail-Demo.git', + :tag => s.version.to_s + } + s.platform = :ios, '7.0' + s.frameworks = ['UIKit'] + s.source_files = 'Classes/*.{h,m}' + s.requires_arc = true + +end \ No newline at end of file