Latest 2.0.0
Homepage https://github.com/google/GOSScrollViewDelegateMultiplexer
License Apache 2.0
Platforms ios 7.0, requires ARC
Authors

MDFScrollViewDelegateMultiplexer

Build Status

This class acts as a proxy object for UIScrollViewDelegate events and forwards all received
events to an ordered list of registered observers.

Installation

Requirements

  • Xcode 7.0 or higher.
  • iOS SDK version 7.0 or higher.

Installation with CocoaPods

To add this component to your Xcode project using CocoaPods, add the following to your Podfile:

pod 'MDFScrollViewDelegateMultiplexer'

Then, run the following command:

pod install

Overview

When a UIScrollViewDelegate method invocation is received by the multiplexer, the multiplexer
forwards the invocation to each observer in order of registration.

If the scroll view method signature has a return value, after all delegate method invocations,
the return value will be provided by the first observing delegate that responded. If no
observers implement the method, a default return value will be used.

However, if a combiner is set and the receiving class conforms to the
MDFScrollViewDelegateCombining protocol, then the receiving class can designate which result
value to return via the use of the optional protocol methods.


Usage

#import "MDFScrollViewDelegateMultiplexer.h"

_multiplexer = [[MDFScrollViewDelegateMultiplexer alloc] init];
myScrollView.delegate = _multiplexer;
[_multiplexer addObservingDelegate:myControl];
[_multiplexer addObservingDelegate:anotherControl];

Using the MDFScrollViewDelegateCombining protocol

First conform to the MDFScrollViewDelegateCombining protocol:

@interface MyViewController () <MDFScrollViewDelegateCombining>
@end

[_multiplexer setCombiner:self];

Handle one of the UIScrollViewDelegate protocol methods that return a value:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
  return myZoomingView;
}

And finally return the desired observer’s results from the combiner method:

- (UIView *)scrollViewDelegateMultiplexer:(MDFScrollViewDelegateMultiplexer *)multiplexer
                viewForZoomingWithResults:(NSPointerArray *)results
                  fromRespondingObservers:(NSArray *)respondingObservers {
  // Lets return the results from the observer which is equal to self.
  if (respondingObservers[0] == self) {
    return [results pointerAtIndex:0];
  }
  return nil;
}

Latest podspec

{
    "name": "GOSScrollViewDelegateMultiplexer",
    "version": "2.0.0",
    "authors": {
        "Chris Cox": "[email protected]"
    },
    "summary": "A proxy object for UIScrollViewDelegate that forwards all received events to an ordered list of registered observers.",
    "homepage": "https://github.com/google/GOSScrollViewDelegateMultiplexer",
    "license": "Apache 2.0",
    "source": {
        "git": "https://github.com/google/GOSScrollViewDelegateMultiplexer.git",
        "tag": "2.0.0"
    },
    "platforms": {
        "ios": "7.0"
    },
    "requires_arc": true,
    "deprecated_in_favor_of": "MDFScrollViewDelegateMultiplexer",
    "public_header_files": "src/*.h",
    "source_files": "src/*.{h,m}"
}

Pin It on Pinterest

Share This