Added delegate to have the client notified when a contraction or expansion finishes animating.

This commit is contained in:
Gian Franco Zabarino 2015-05-05 16:41:04 -03:00
parent d975745250
commit 2e065ac823
2 changed files with 35 additions and 2 deletions

View File

@ -9,6 +9,8 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@protocol TLYShyNavBarManagerDelegate;
/* CLASS DESCRIPTION: /* CLASS DESCRIPTION:
* ================== * ==================
* Manages the relationship between a scrollView and a view * Manages the relationship between a scrollView and a view
@ -55,6 +57,24 @@
@property (nonatomic) BOOL disable; @property (nonatomic) BOOL disable;
/* Use this to be notified about contraction and expansion events.
*/
@property (nonatomic, weak) id<TLYShyNavBarManagerDelegate> delegate;
@end
/* PROTOCOL DESCRIPTION:
* =====================
* This protocol is used to notify an optional TLYShyNavBarManager's delegate
* when a contraction or expansion finishes animating.
*/
@protocol TLYShyNavBarManagerDelegate <NSObject>
@optional
- (void)shyNavBarManagerDidFinishContracting:(TLYShyNavBarManager *) shyNavBarManager;
- (void)shyNavBarManagerDidFinishExpanding:(TLYShyNavBarManager *) shyNavBarManager;
@end @end

View File

@ -315,10 +315,23 @@ static inline CGFloat AACStatusBarHeight()
CGPoint newContentOffset = self.scrollView.contentOffset; CGPoint newContentOffset = self.scrollView.contentOffset;
newContentOffset.y -= deltaY; newContentOffset.y -= deltaY;
__weak typeof(self) weakSelf = self;
[UIView animateWithDuration:0.2 [UIView animateWithDuration:0.2
animations:^{ animations:^{
self.scrollView.contentOffset = newContentOffset; weakSelf.scrollView.contentOffset = newContentOffset;
}
completion:^(BOOL finished) {
typeof(weakSelf) strongSelf = weakSelf;
if (strongSelf.isContracting) {
if ([strongSelf.delegate respondsToSelector:@selector(shyNavBarManagerDidFinishContracting:)]) {
[strongSelf.delegate shyNavBarManagerDidFinishContracting:strongSelf];
}
} else {
if ([strongSelf.delegate respondsToSelector:@selector(shyNavBarManagerDidFinishExpanding:)]) {
[strongSelf.delegate shyNavBarManagerDidFinishExpanding:strongSelf];
}
}
}]; }];
} }