Change Delegate to @optional

This commit is contained in:
Kyle Fang
2013-02-26 14:25:30 +08:00
parent 94a1cc4264
commit a90d22886e
2 changed files with 22 additions and 12 deletions

View File

@@ -9,11 +9,13 @@
#import <UIKit/UIKit.h>
@protocol ZGDragViewDelegate <NSObject>
@optional
- (void)dragView:(UIView *)dragView Show:(CGFloat )showPixels ofTotal:(CGFloat )totalPixels;
- (void)dragView:(UIView *)dragView hangForCompletionBlock:(void (^)())completed;
@end
@protocol ZGPullViewDelegate <NSObject>
@optional
- (void)pullView:(UIView *)pullView Show:(CGFloat )shownPixels ofTotal:(CGFloat )totalPixels;
- (void)pullView:(UIView *)pullView hangForCompletionBlock:(void (^)())completed;
@end

View File

@@ -131,38 +131,46 @@ static char UITableViewZGDragView;
}
- (void)pullViewHandler:(CGFloat )visiblePixels{
[self.ZGPullViewDelegate pullView:self.pullView Show:visiblePixels ofTotal:self.pullView.frame.size.height];
if ([self.ZGPullViewDelegate respondsToSelector:@selector(pullView:Show:ofTotal:)]) {
[self.ZGPullViewDelegate pullView:self.pullView Show:visiblePixels ofTotal:self.pullView.frame.size.height];
}
if (visiblePixels>self.pullView.frame.size.height && !self.isDragging) {
[UIView animateWithDuration:0.1
animations:^{
self.contentInset = UIEdgeInsetsMake(self.pullView.frame.size.height, 0, 0, 0);
} completion:^(BOOL finished) {
[self.ZGPullViewDelegate pullView:self.pullView hangForCompletionBlock:^{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[UIView animateWithDuration:0.2 animations:^{
self.contentInset = UIEdgeInsetsZero;
if ([self.ZGPullViewDelegate respondsToSelector:@selector(pullView:hangForCompletionBlock:)]) {
[self.ZGPullViewDelegate pullView:self.pullView hangForCompletionBlock:^{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[UIView animateWithDuration:0.2 animations:^{
self.contentInset = UIEdgeInsetsZero;
}];
}];
}];
}];
}
}];
}
}
- (void)dragViewHandler:(CGFloat )visiblePixels{
[self.ZGDragViewDelegate dragView:self.dragView Show:visiblePixels ofTotal:self.dragView.frame.size.height];
if ([self.ZGDragViewDelegate respondsToSelector:@selector(dragView:Show:ofTotal:)]) {
[self.ZGDragViewDelegate dragView:self.dragView Show:visiblePixels ofTotal:self.dragView.frame.size.height];
}
if (visiblePixels>self.dragView.frame.size.height && !self.isDragging) {
[UIView animateWithDuration:0.1
animations:^{
self.contentInset = UIEdgeInsetsMake(0, 0, self.dragView.frame.size.height, 0);
} completion:^(BOOL finished) {
[self.ZGDragViewDelegate dragView:self.dragView hangForCompletionBlock:^{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[UIView animateWithDuration:0.2 animations:^{
self.contentInset = UIEdgeInsetsZero;
if ([self.ZGDragViewDelegate respondsToSelector:@selector(dragView:hangForCompletionBlock:)]) {
[self.ZGDragViewDelegate dragView:self.dragView hangForCompletionBlock:^{
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[UIView animateWithDuration:0.2 animations:^{
self.contentInset = UIEdgeInsetsZero;
}];
}];
}];
}];
}
}];
}
}