PUMenuView 1.0.5

PUMenuView 1.0.5

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布上次发布2016 年 11 月

王晶涵 维护。




PUMenuView 是一个“tumblr”风格的弹出菜单视图。它使用 Objective C 构建,并完全支持 自动布局。使用 PUMenuView,您可以轻松地动画菜单,添加您想要的任意数量的菜单项。

ios simulator screen shot 2015 6 15 00 50 32

数据源方法

必要
-(NSInteger)numberOfItemsInMenuView:(PUMenuView *)menuView;

此方法必不可少,因为它向视图提供需要显示多少个菜单项的信息。由于这是菜单布局其子视图必须有的信息,因此它必须由数据源实例实现。

可选
-(UIButton *)menuView:(PUMenuView *)menuView buttonForItemAtIndex:(NSInteger)index;

此方法为菜单提供了它需要显示的按钮。这些按钮将作为菜单内的菜单项使用。在传递按钮之后,菜单视图将按索引对它们进行索引,并将索引分配给它们的标签。当按钮被点击时,将调用代理方法 menuView: itemDidSelectAtIndex:

-(UIView *)menuView:(PUMenuView *)menuView viewForItemAtIndex:(NSInteger)index;

此方法为菜单提供需要显示的自定义视图。此方法比 menuView:menuView buttonForItemAtIndex: 的优先级低,这意味着当在数据源中实现了 menuView:buttonForItemAtIndex: 时,此方法不会被调用。在传递视图之后,菜单视图将把一个 UITapGestureRecognizer 绑定到该视图。一旦视图被点击,将触发代理 menuView:itemDidSelectAtIndex:

代理方法

- (void)menuView:(PUMenuView *)menuView itemDidSelectAtIndex:(NSInteger)index;
- (void)menuViewWillShow:(PUMenuView *)menuView;
- (void)menuViewDidShow:(PUMenuView *)menuView;
- (void)menuViewWillHide:(PUMenuView *)menuView;
- (void)menuViewDidHide:(PUMenuView *)menuView;

参数

@property (nonatomic, weak) NSObject<PUMenuViewDelegate> *delegate;
@property (nonatomic, weak) NSObject<PUMenuViewDataSource> *dataSource;

@property (nonatomic) UIView *backgroundView;

//behavior
@property (nonatomic) BOOL menuShouldHideAfterSelection;

//state
@property (nonatomic) BOOL isAnimationPresenting;
@property (nonatomic) BOOL isHidden;
@property (nonatomic) BOOL readyForShowing;

//animation (show & hide)
@property (nonatomic) CGFloat animationUnitDelay;
@property (nonatomic) CGFloat animationSpringDamping;
@property (nonatomic) CGFloat animationDuration;
@property (nonatomic) NSArray *animationOrder;

//layout
@property (nonatomic) NSInteger numberOfColumns;
@property (nonatomic) CGFloat itemSideLengthMultiplier;
@property (nonatomic) CGFloat verticalSpaceMultiplier;
@property (nonatomic) CGFloat horizontalMarginMultiplier;
@property (nonatomic, readonly) CGFloat horizontalSpacingMultiplier;

PUMenuItem

PUMenuItem 是一个结合了 UIButton 实例和 UILabel 实例的容器。通过数据源方法 menuView:viewForItemAtIndex:PUMenuItem 传递给 PUMenuView 时,内 PUMenuItem 的 UIControlEvent 将由菜单视图拾取,并通过代理方法 menuView:itemDidSelectAtIndex: 传递给视图。

参数

@property (nonatomic) UIButton *button;
@property (nonatomic) UILabel *label;