Skip to content
This repository was archived by the owner on Dec 14, 2021. It is now read-only.

Commit 7979836

Browse files
committed
Adds example using the combiner protocol. Closes #1.
1 parent 2c6a97a commit 7979836

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,32 @@ myScrollView.delegate = _multiplexer;
5353
[_multiplexer addObservingDelegate:myControl];
5454
[_multiplexer addObservingDelegate:anotherControl];
5555
```
56+
57+
## Using the `GOSScrollViewDelegateCombining` protocol
58+
59+
First conform to the `GOSScrollViewDelegateCombining` protocol:
60+
61+
```objectivec
62+
@interface MyViewController () <GOSScrollViewDelegateCombining>
63+
@end
64+
65+
[_multiplexer setCombiner:self];
66+
```
67+
68+
Handle one of the `UIScrollViewDelegate` protocol methods that return a value:
69+
70+
```objectivec
71+
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
72+
return myZoomingView;
73+
}
74+
```
75+
76+
And finally return the desired observer's results from the combiner method:
77+
78+
```objectivec
79+
- (UIView *)scrollViewDelegateMultiplexer:(GOSScrollViewDelegateMultiplexer *)multiplexer
80+
viewForZoomingWithResults:(NSPointerArray *)results
81+
fromRespondingObservers:(NSArray *)respondingObservers {
82+
return [results pointerAtIndex:0];
83+
}
84+
```

examples/SVDMTypicalUseViewController.m

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626
#define RGBCOLOR(r, g, b) [UIColor colorWithRed:(r) / 255.0f green:(g) / 255.0f blue:(b) / 255.0f alpha:1]
2727
#define HEXCOLOR(hex) RGBCOLOR((((hex) >> 16) & 0xFF), (((hex) >> 8) & 0xFF), ((hex)&0xFF))
2828

29+
@interface SVDMTypicalUseViewController () <GOSScrollViewDelegateCombining>
30+
@end
31+
2932
@implementation SVDMTypicalUseViewController {
3033
UIScrollView *_scrollView;
3134
UIPageControl *_pageControl;
3235
NSArray *_pageColors;
33-
3436
GOSScrollViewDelegateMultiplexer *_multiplexer;
3537
}
3638

@@ -52,18 +54,22 @@ - (void)viewDidLoad {
5254
_scrollView.pagingEnabled = YES;
5355
_scrollView.contentSize = CGSizeMake(boundsWidth * _pageColors.count, boundsHeight);
5456
_scrollView.minimumZoomScale = 0.5;
55-
_scrollView.maximumZoomScale = 6.0;
57+
_scrollView.maximumZoomScale = 1.5;
5658

5759
// Add pages to scrollView.
5860
for (NSInteger i = 0; i < _pageColors.count; i++) {
5961
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];
6563
page.backgroundColor = _pageColors[i];
6664
[_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];
6773
}
6874

6975
// Page control configuration
@@ -101,6 +107,19 @@ - (void)viewDidLoad {
101107
_scrollView.delegate = _multiplexer;
102108
[_multiplexer addObservingDelegate:self];
103109
[_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;
104123
}
105124

106125
#pragma mark - UIScrollViewDelegate
@@ -111,6 +130,12 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
111130
[_pageControl updateCurrentPageDisplay];
112131
}
113132

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+
114139
#pragma mark - User events
115140

116141
- (void)didChangePage:(UIPageControl *)sender {

0 commit comments

Comments
 (0)