26
26
#define RGBCOLOR (r, g, b ) [UIColor colorWithRed: (r) / 255 .0f green: (g) / 255 .0f blue: (b) / 255 .0f alpha: 1 ]
27
27
#define HEXCOLOR (hex ) RGBCOLOR((((hex) >> 16 ) & 0xFF ), (((hex) >> 8 ) & 0xFF ), ((hex)&0xFF ))
28
28
29
+ @interface SVDMTypicalUseViewController () <GOSScrollViewDelegateCombining>
30
+ @end
31
+
29
32
@implementation SVDMTypicalUseViewController {
30
33
UIScrollView *_scrollView;
31
34
UIPageControl *_pageControl;
32
35
NSArray *_pageColors;
33
-
34
36
GOSScrollViewDelegateMultiplexer *_multiplexer;
35
37
}
36
38
@@ -52,18 +54,22 @@ - (void)viewDidLoad {
52
54
_scrollView.pagingEnabled = YES ;
53
55
_scrollView.contentSize = CGSizeMake (boundsWidth * _pageColors.count , boundsHeight);
54
56
_scrollView.minimumZoomScale = 0.5 ;
55
- _scrollView.maximumZoomScale = 6.0 ;
57
+ _scrollView.maximumZoomScale = 1.5 ;
56
58
57
59
// Add pages to scrollView.
58
60
for (NSInteger i = 0 ; i < _pageColors.count ; i++) {
59
61
CGRect pageFrame = CGRectOffset (self.view .bounds , i * boundsWidth, 0 );
60
- UILabel *page = [[UILabel alloc ] initWithFrame: pageFrame];
61
- page.text = [NSString stringWithFormat: @" Page %zd " , i + 1 ];
62
- page.font = [UIFont systemFontOfSize: 50 ];
63
- page.textColor = [UIColor colorWithWhite: 0 alpha: 0.8 ];
64
- page.textAlignment = NSTextAlignmentCenter;
62
+ UIView *page = [[UIView alloc ] initWithFrame: pageFrame];
65
63
page.backgroundColor = _pageColors[i];
66
64
[_scrollView addSubview: page];
65
+
66
+ UILabel *pageTitle = [[UILabel alloc ] initWithFrame: page.bounds];
67
+ pageTitle.text = [NSString stringWithFormat: @" Page %zd " , i + 1 ];
68
+ pageTitle.font = [UIFont systemFontOfSize: 50 ];
69
+ pageTitle.textColor = [UIColor colorWithWhite: 0 alpha: 0.8 ];
70
+ pageTitle.textAlignment = NSTextAlignmentCenter;
71
+ pageTitle.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
72
+ [page addSubview: pageTitle];
67
73
}
68
74
69
75
// Page control configuration
@@ -101,6 +107,19 @@ - (void)viewDidLoad {
101
107
_scrollView.delegate = _multiplexer;
102
108
[_multiplexer addObservingDelegate: self ];
103
109
[_multiplexer addObservingDelegate: pageControl];
110
+ [_multiplexer setCombiner: self ];
111
+ }
112
+
113
+ #pragma mark - GOSScrollViewDelegateCombining
114
+
115
+ - (UIView *)scrollViewDelegateMultiplexer : (GOSScrollViewDelegateMultiplexer *)multiplexer
116
+ viewForZoomingWithResults : (NSPointerArray *)results
117
+ fromRespondingObservers : (NSArray *)respondingObservers {
118
+ // Lets return the results from the oberserver which is equal to self.
119
+ if (respondingObservers[0 ] == self) {
120
+ return [results pointerAtIndex: 0 ];
121
+ }
122
+ return nil ;
104
123
}
105
124
106
125
#pragma mark - UIScrollViewDelegate
@@ -111,6 +130,12 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
111
130
[_pageControl updateCurrentPageDisplay ];
112
131
}
113
132
133
+ - (UIView *)viewForZoomingInScrollView : (UIScrollView *)scrollView {
134
+ // Since there are multiple observers, we will allow the combiner to return this page
135
+ // as the zooming view.
136
+ return scrollView.subviews [_pageControl.currentPage];
137
+ }
138
+
114
139
#pragma mark - User events
115
140
116
141
- (void )didChangePage : (UIPageControl *)sender {
0 commit comments