Peekaboo是一个iOS API,它允许您通过可选的代理方法轻松使用UIScrollView来自动隐藏您配置的导航栏、工具栏或其他UIView。
要运行示例项目,首先从仓库中克隆,然后在Example目录中运行pod install
。
Peekaboo可以通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中
pod "Peekaboo"
Peekaboo旨在简单易用,对于大多数使用情况可以通过一行代码进行配置,但也提供通过代理实现额外的灵活性。它与其他值得注意的API的不同之处在于它假定很少,如果需要的话,可以使用标准方式隐藏导航栏和工具栏,或者允许您在自己的定制代理方法中执行必要的转换,无需子类。这个API的需求源于其他API已经完成了90%的需要的任务,但因为它非常定制,需要修改代码以适应我的场景。因此,这个API是为检测/配置由UIScrollView触发的事件而设计的,以便通知“视口”应该扩展或收缩,仅此而已。以下是如何进行其余的操作
#import <Peekaboo/Peekaboo.h>
@interface YourViewController : UIViewController <NEIPeekabooDelegate>
@end
@implementation YourViewController
- (void) viewDidLoad {
[super viewDidLoad];
[self enablePeekabooUsingScrollView:scrollView
mask:NEIPeekabooAutomaximizeNavigatorBar | NEIPeekabooAutomaximizeToolbar
delegate:self];
}
/******************************************************************************************************************
Following methods have no relation with optional mask NEIPeekabooAutomaximizeNavigatorBar and NEIPeekabooAutomaximizeToolbar,
but can used to instead of or in conjuction with mask to expand or contract views to maximize space. Mask if provided,
allow you to not have to hide or show respective controllers manually, but if provided, are maniuplated using standard
show/hide navigation and toolbar methods. If used, you must conform to NEIPeekabooDelegate protocol.
******************************************************************************************************************/
#pragma mark - NEIPeekabooDelegate
- (BOOL)peekabooViewportIsMaximized {
// optional: you can use any logic to determine if its maximized, otherwise internal logic is used of not implemented
return self.navigationController.navigationBarHidden;
}
- (BOOL)peekabooShouldAlterViewport:(id)scrollView maximized:(BOOL)maximized {
return YES; //optional: always defaults to YES
}
- (void)peekabooWillAlterViewport:(id)scrollView maximized:(BOOL)maximized {
//optional: You can add your own code that will add/reduce available space.
}
- (void)peekabooDidAlterViewport:(id)scrollView maximized:(BOOL)maximized {
//optional: You can add your own code that will add/reduce available space.
}
@end
James Whitfield, valerius (at) neilab.com
Peekaboo在MIT许可协议下可用。有关更多信息,请参阅LICENSE文件。