MMMHorizontalPickerDelegate

Objective-C

@protocol MMMHorizontalPickerDelegate <NSObject>

Swift

protocol MMMHorizontalPickerDelegate : NSObjectProtocol
  • The total number of items. Note that this is read only once, when reload is called.

    Declaration

    Objective-C

    - (NSInteger)numberOfItemsForHorizontalPicker:
        (nonnull MMMHorizontalPicker *)picker;

    Swift

    func numberOfItemsForHorizontalPicker(_ picker: MMMHorizontalPicker) -> Int
  • The delegate must provide a view showing the given item, it should use Auto Layout and at least the width should be defined.

    Declaration

    Objective-C

    - (nonnull UIView *)horizontalPicker:(nonnull MMMHorizontalPicker *)picker
                    viewForItemWithIndex:(NSInteger)index;

    Swift

    func horizontalPicker(_ picker: MMMHorizontalPicker, viewForItemWith index: Int) -> UIView
  • Undocumented

    Declaration

    Objective-C

    - (void)horizontalPickerDidChangeCurrentItemIndex:(MMMHorizontalPicker *)picker;

    Swift

    func horizontalPickerDidChangeCurrentItemIndex(_ picker: MMMHorizontalPicker)
  • Called after an item view becomes invisible and is removed from the picker.

    • The delegate can choose to store it somewhere and reuse it later or can just forget it and simply use a new view next time.

    Declaration

    Objective-C

    - (void)horizontalPicker:(nonnull MMMHorizontalPicker *)picker
                 recycleView:(nonnull UIView *)view;

    Swift

    optional func horizontalPicker(_ picker: MMMHorizontalPicker, recycle view: UIView)
  • Called after the given item view is added into the view hierarchy.

    Declaration

    Objective-C

    - (void)horizontalPicker:(nonnull MMMHorizontalPicker *)picker
                 prepareView:(nonnull UIView *)view;

    Swift

    optional func horizontalPicker(_ picker: MMMHorizontalPicker, prepare view: UIView)
  • Called every time the viewport position changes (every frame in case of animation or dragging) with an updated “center proximity” value for each visible item view.

    “Center proximity” is a difference between the center of the item and the current viewport position in “index space” coordinates.

    For example, if the current item is in the center of the view port already, then its “center proximiy” value will be 0, and the same value for the view right (left) to the central item will be 1 (-1). When dragging the contents so the right view gets closer to the center, then its center proximity will be continously approaching 0.

    This is handy when you need to dim or transforms items when they get farther from the center, but be careful with doing heavy things here.

    Declaration

    Objective-C

    - (void)horizontalPicker:(nonnull MMMHorizontalPicker *)picker
                  updateView:(nonnull UIView *)view
             centerProximity:(CGFloat)centerProximity;

    Swift

    optional func horizontalPicker(_ picker: MMMHorizontalPicker, update view: UIView, centerProximity: CGFloat)
  • Called when the picker scrolls to a new offset.

    Declaration

    Objective-C

    - (void)horizontalPicker:(nonnull MMMHorizontalPicker *)picker
                   didScroll:(CGFloat)offset;

    Swift

    optional func horizontalPicker(_ picker: MMMHorizontalPicker, didScroll offset: CGFloat)