2626
2727static CGFloat kThreshold = 80 ;
2828
29- static CGFloat sCurrentYOffset = 0 ;
30- static CGFloat sBeginYOffset = 0 ;
31- static CGFloat sEndYOffset = 0 ;
32- static UILabel *sLabelInfo = nil ;
33- static UIView *sContainerView = nil ;
29+ @interface DDParsecServiceCollectionViewController : UINavigationController <UITableViewDelegate>
30+ - (void )doneButtonPressed : (id )arg1 ;
31+ @end
32+
33+ static DDParsecServiceCollectionViewController * sController ;
34+
35+ namespace {
36+ class ScrollHelper
37+ {
38+ public:
39+ CGFloat sBeginYOffset = 0 ;
40+ CGFloat sEndYOffset = 0 ;
41+ UILabel *sLabelInfo = nil ;
42+ UIView *sContainerView = nil ;
43+ bool sTipPositionFirstPage = true ;
44+ bool sEnable = false ;
45+
46+ void scrollViewDidScroll (UIScrollView * scrollView){
47+ if (!sEnable )return ;
48+
49+ if (sBeginYOffset != 0 ){
50+ CGFloat length = scrollView.contentOffset .y - sBeginYOffset ;
51+ // NSLog(@"qiweidict : offset length = %@",@(length));
52+ if (fabs (length) > kThreshold && length < 0 ){
53+ if (!sLabelInfo && sContainerView ){
54+ CGSize screenSize = [UIScreen mainScreen ].bounds .size ;
55+ sLabelInfo = [[UILabel alloc ]init];
56+ sLabelInfo .bounds = CGRectMake (0 , 0 , 130 , 20 );
57+ if (sTipPositionFirstPage ){
58+ sLabelInfo .center = CGPointMake (screenSize.width / 2 , -10 );
59+ }else {
60+ sLabelInfo .center = CGPointMake (screenSize.width / 2 , 100 );
61+ }
62+ sLabelInfo .text = @" release to close" ;
63+ sLabelInfo .textColor = [UIColor grayColor ];
64+ [sContainerView addSubview: sLabelInfo ];
65+ }
66+ }else {
67+ if (sLabelInfo ){
68+ [sLabelInfo removeFromSuperview ];
69+ sLabelInfo = nil ;
70+ }
71+
72+ }
73+ }
74+ }
75+ void scrollViewWillBeginDragging (UIScrollView * scrollView){
76+ // NSLog(@"qiweidict : begin %@",@(scrollView.contentOffset.y));
77+ if (scrollView.contentOffset .y <= 0 )sEnable = true ;
78+ else sEnable = false ;
79+ if (!sEnable )return ;
80+
81+ sBeginYOffset = scrollView.contentOffset .y ;
82+ // NSLog(@"qiweidict : begin drag = %@",@(sBeginYOffset));
83+ }
84+ void scrollViewWillEndDragging (UIScrollView * scrollView, void (^done)()){
85+ if (!sEnable )return ;
86+ sEndYOffset = scrollView.contentOffset .y ;
87+ CGFloat length = sEndYOffset - sBeginYOffset ;
88+ // NSLog(@"qiweidict : end drag = %@, length = %@",@(sEndYOffset), @(length));
89+
90+ if (sEndYOffset < sBeginYOffset && fabs (length) > kThreshold && length < 0 ){
91+ // NSLog(@"qiweidict : should pull down to close");
92+ if (done) done ();
93+ }
94+
95+ sBeginYOffset = 0 ;
96+ sEndYOffset = 0 ;
97+ }
98+ };
99+ }
100+
101+ static ScrollHelper a;
102+ static ScrollHelper b;
103+
34104
35105// ////////////////////////////////////////////////////////////////////////////////////////////////////
36106@interface DDParsecTableViewController : UITableViewController
@@ -41,45 +111,23 @@ @interface DDParsecTableViewController : UITableViewController
41111
42112CHOptimizedMethod (1 , self, void , DDParsecTableViewController, viewDidAppear,BOOL ,value1)
43113{
44- sContainerView = self.view ;
45- NSLog (@" qiweidict : first page viewDidAppear %@ " ,self);
114+ // NSLog(@"qiweidict : first page viewDidAppear %@ , navi = %@",self,self.navigationController);
115+ a.sContainerView = self.view ;
116+ a.sTipPositionFirstPage = true ;
117+ sController = (DDParsecServiceCollectionViewController *)self.navigationController ;
118+
46119 CHSuper (1 , DDParsecTableViewController, viewDidAppear, value1);
47120}
48121
49122// ////////////////////////////////////////////////////////////////////////////////////////////////////
50123
51- @interface DDParsecServiceCollectionViewController : UINavigationController <UITableViewDelegate>
52- - (void )doneButtonPressed : (id )arg1 ;
53- @end
54124
55125@class DDParsecServiceCollectionViewController;
56126CHDeclareClass (DDParsecServiceCollectionViewController); // declare class
57127
58128CHOptimizedMethod (1 , self, void , DDParsecServiceCollectionViewController, scrollViewDidScroll,UIScrollView*,scrollView)
59129{
60- // NSLog(@"qiweidict : content offset = %@",@(scrollView.contentOffset.y));
61- sCurrentYOffset = scrollView.contentOffset .y ;
62- if (sBeginYOffset != 0 ){
63- CGFloat length = fabs (sCurrentYOffset - sBeginYOffset );
64- NSLog (@" qiweidict : offset length = %@ " ,@(length));
65- if (length > kThreshold ){
66- if (!sLabelInfo && sContainerView ){
67- CGSize screenSize = [UIScreen mainScreen ].bounds .size ;
68- sLabelInfo = [[UILabel alloc ]init];
69- sLabelInfo .bounds = CGRectMake (0 , 0 , 130 , 20 );
70- sLabelInfo .center = CGPointMake (screenSize.width / 2 , -10 );
71- sLabelInfo .text = @" Release to close" ;
72- sLabelInfo .textColor = [UIColor grayColor ];
73- [sContainerView addSubview: sLabelInfo ];
74- }
75- }else {
76- if (sLabelInfo ){
77- [sLabelInfo removeFromSuperview ];
78- sLabelInfo = nil ;
79- }
80-
81- }
82- }
130+ a.scrollViewDidScroll (scrollView);
83131 CHSuper (1 , DDParsecServiceCollectionViewController, scrollViewDidScroll,scrollView);
84132}
85133
@@ -89,20 +137,12 @@ @interface DDParsecServiceCollectionViewController (dictionarypulldowntoclose)
89137@implementation DDParsecServiceCollectionViewController (dictionarypulldowntoclose)
90138
91139- (void )scrollViewWillBeginDragging : (UIScrollView *)scrollView {
92- sBeginYOffset = sCurrentYOffset ;
93- NSLog (@" qiweidict : begin drag = %@ " ,@(sBeginYOffset ));
140+ a.scrollViewWillBeginDragging (scrollView);
94141}
95142- (void )scrollViewWillEndDragging : (UIScrollView *)scrollView withVelocity : (CGPoint)velocity targetContentOffset : (inout CGPoint *)targetContentOffset {
96- sEndYOffset = sCurrentYOffset ;
97- CGFloat length = fabs (sEndYOffset - sBeginYOffset );
98- NSLog (@" qiweidict : end drag = %@ , length = %@ " ,@(sEndYOffset ), @(length));
99-
100- if (sEndYOffset < sBeginYOffset && length > kThreshold ){
101- NSLog (@" qiweidict : should pull down to close" );
143+ a.scrollViewWillEndDragging (scrollView,^{
102144 [self doneButtonPressed: nil ];
103- }
104-
105- sBeginYOffset = 0 ;
145+ });
106146}
107147
108148@end
@@ -116,11 +156,18 @@ @interface DUEntryViewController (dictionarypulldowntoclose)
116156@end
117157@implementation DUEntryViewController (dictionarypulldowntoclose)
118158- (void )scrollViewDidScroll : (UIScrollView *)scrollView {
119- NSLog (@" qiweidict: did scroll : %@ " ,@(scrollView.contentOffset.y));
159+ // NSLog(@"qiweidict: did scroll : %@",@(scrollView.contentOffset.y));
160+ b.sTipPositionFirstPage = false ;
161+ b.scrollViewDidScroll (scrollView);
120162}
121163- (void )scrollViewWillBeginDragging : (UIScrollView *)scrollView {
164+ b.scrollViewWillBeginDragging (scrollView);
122165}
123166- (void )scrollViewWillEndDragging : (UIScrollView *)scrollView withVelocity : (CGPoint)velocity targetContentOffset : (inout CGPoint *)targetContentOffset {
167+ b.scrollViewWillEndDragging (scrollView,^{
168+ // NSLog(@"qiweidict : need close now");
169+ [sController doneButtonPressed: nil ];
170+ });
124171}
125172@end
126173
@@ -129,9 +176,11 @@ - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoi
129176
130177CHOptimizedMethod (0 , self, void , DUEntryViewController, viewDidLoad)
131178{
132- NSLog (@" qiweidict : detail viewDidLoad %p %@ " ,self,self);
179+ // NSLog(@"qiweidict : detail viewDidLoad %p %@",self,self);
133180 CHSuper (0 , DUEntryViewController, viewDidLoad);
134181
182+ b.sContainerView = self.view ;
183+
135184 UIView *view = self.view ;
136185 if (view.subviews .count > 0 ){
137186 UIWebView *webView = view.subviews [0 ];
0 commit comments