AKInteractiveBarProxy 库提供了一个代理对象,该对象可以帮您在 UIScrollView 上创建类似 Safari 的交互式动画栏。该代理作为 UIScrollView 及其子类的代理对象与用户输入进行交互。一旦用户在滚动视图中滚动,AKInteractiveBarProxy 将分析滚动手势并解析它作为交互式动画传递给其代理。
CocoaPods (尚未可用)
使用您的滚动视图实例化 AKInteractiveBarProxy。
// Instaciate the target scroll view (or subclasses of scroll view, like table view).
self.scrollView = [[UIScrollView alloc] initWithFrame:self.contentView.bounds];
[self.contentView addSubView:scrollView];
// Provide a proxy
// interactionTranslation defines how far users have to pan before interaction is complete.
self.interactiveBarProxy = [[AKInteractiveBarProxy alloc] initWithScrollView:self.scrollView
delegate:self];
self.interactiveBarProxy.interactionTranslation = 64.0;
完成设置后,实现代理的委托方法。您也可以实现 UIScrollViewDelegate,因为 AKInteractiveBarProxyDelegate 确认了 UIScrollViewDelegate。
// Implement delegate methods
- (void)proxy:(AKInteractiveBarProxy *)proxy receivedInteractiveGestureWithProgress:(CGFloat)progress
{
// This delegate is called when the proxy detects interactive gestures.
// Implement your interactive animation here.
// Note this method is gets called until user stops interactions.
// progress 0.0 = Your bar should be completely hidden
// progress 1.0 = Your bar should be completely visible
self.bar.alpha = progress;
}
- (void)proxy:(AKInteractiveBarProxy *)proxy receivedNonInteractiveActionWithBarHidden:(BOOL)hidden
{
// This delegate is called when the proxy detects non-interactive onetime actions.
// You should programmatically show/hide your views here.
[self.bar setHidden:hidden animated:YES];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// This will also gets called. Do anything you want!
}