KYAnimatedPageControl 1.0.5

KYAnimatedPageControl 1.0.5

测试测试
语言语言 Obj-CObjective C
许可 MIT
发布最新发布2015 年 6 月

KittenYang 维护。



  • 作者:
  • KittenYang

介绍

一个带有多个动画的自定义 UIPageControl。具有两种动画风格:)

(自定义的 UIPageControl。有两种动画样式:)

  • 粘性小球

  • 粘性小球

gooeyCircle

细节

气泡移动的距离越长,其粘性效果越强烈。

粘性小球会根据移动距离的大小拥有不同的弹性程度。移动距离越大,弹性效果越明显。

  • 旋转方块
  • 旋转方块

rotateRect

您不仅可以在滚动 UIScrollView 子类(如 UICollectionView、UITableView)时,KYAnimatedPageControl 也会自动以动画的形式移动,还可以直接在 KYAnimatedPageControl 上点击目标页面,此时 UIScrollView 也会自动且智能地滚动到目标位置。

KYAnimatedPageControl 不仅可以在您滑动 UIScrollView 的时候自动以动画的形式移动,而且您还可以直接在 KYAnimatedPageControl 上的点击要滚动到的目标页,此时除了 KYAnimatedPageControl 会以动画的形式移动,UIScrollView 也会很智能地滑到目标页面。

博客

谈谈 iOS 中粘性动画以及果冻效果的实现

安装

pod 'KYAnimatedPageControl', '~> 1.0.4'

用法

初始化

    self.pageControl = [[KYAnimatedPageControl alloc]initWithFrame:CGRectMake(20, 450, 280, 50)];
    self.pageControl.pageCount = 8;
    self.pageControl.unSelectedColor = [UIColor colorWithWhite:0.9 alpha:1];
    self.pageControl.selectedColor = [UIColor redColor];
    self.pageControl.bindScrollView = self.demoCollectionView;
    self.pageControl.shouldShowProgressLine = YES;

    self.pageControl.indicatorStyle = IndicatorStyleGooeyCircle;
    self.pageControl.indicatorSize = 20;
    [self.pageControl display];
    [self.view addSubview:self.pageControl];

必须实现的 UIScrollViewDelegate 方法

#pragma mark -- UIScrollViewDelegate
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

    //Indicator动画
    [self.pageControl.indicator animateIndicatorWithScrollView:scrollView andIndicator:self.pageControl];

    if (scrollView.dragging || scrollView.isDecelerating || scrollView.tracking) {
        //背景线条动画
        [self.pageControl.pageControlLine animateSelectedLineWithScrollView:scrollView];
    }

}


-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{


    self.pageControl.indicator.lastContentOffset = scrollView.contentOffset.x;

}

-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{


    [self.pageControl.indicator restoreAnimation:@(1.0/self.pageControl.pageCount)];

}

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{
    self.pageControl.indicator.lastContentOffset = scrollView.contentOffset.x;
}

版本

版本

v1.0.4

  • 增加点击某个 Index 的回调。

v1.0.3

  • 取消方块的结束抖动效果(需要可打开注释的代码)
  • 改进判断滑动方向的算法。由之前的(当前 contentOffset.x - 上一次的 contentOffset.x)来判断方向,改成现在的(当前 contentOffset.x - 上一次的 contentOffset.x)是否划过一半来判断方向。
  • 增加 UIPanGesture。现在可以拖动 Indicator 了,小球会跟着你的手指跑了。通过新增的 @property(nonatomic,assign)BOOL swipeEnable; 接口可以选择是否开启拖动手势。
  • 增加一个接口方法。调用可以快速跳到目标页而不用点击。 -(void)animateToIndex:(NSInteger)index;

v1.0.2

  • 增加旋转方块的震动效果

v1.0.1

  • 增加粘性小球样式

v1.0.0

  • 第一次提交:完成旋转方块样式

许可

本项目采用 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。