码迷,mamicode.com
首页 > 其他好文 > 详细

自己封装的轮播工具

时间:2017-06-19 13:15:25      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:count   ring   动画效果   .net   offset   span   function   分析   sch   

近期闲来无事,刚好自己封装了一个轮播的demo,能够实现设置时间间隔,是否轮播。是否显示indicator等。使用的时候直接设置參数就能够了,再也不用那么的麻烦了。

以下结合代码来阐述一下自己的思路吧。首先有两种模式,能够自己主动播放和不自己主动播放两种模式。

-(void)configureScrollPlayer{

    [self backToOriginStatus];

    if (automaticScroll) {

        [self configureWithAutomaticScroll];

    }else{

        [self configureWithNoAutomaticScroll];

    }

}

自己主动播放的时候,自己加入了一个定时器,来循环的播放,另外在自己主动播放的时候还能够滑动来实现切换页面,可是曾经做的时候这个问题是没有注意到的,后来发现两者会有冲突。总感觉用手滑动的时候效果很的堵塞。不是那么的流畅,细致分析了一下,发现时定时器出发的滚动和用手拖拽实现的滚动同一时候触发了。造成了这种现象。我在这里优先用户用手拖拽的效果。

由于用户拖拽的话。肯定是想高速的看到自己想看的东西。


在这里我在UIScrollview的代理方法里加了一个标签开关。isUserDragged =YES;

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

[timer invalidate];
    isUserDragged =YES;


}


- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
    float playerWidth =mainScroll.frame.size.width;
    float lastTargetOffset =pageIndex *playerWidth;
    NSInteger page =(targetContentOffset->x - lastTargetOffset)/playerWidth;
    pageIndex+=page;

//    NSLog(@"pageIndex((((((((((((( %ld",(long)pageIndex);
//    NSLog(@"pageIndex((((((((((((( %ld",(long)pageIndex);

    UIButton *button =(UIButton *)[self viewWithTag:(101+pageIndex)];

    [self pageIndicatorClicked:button];

       timer =[NSTimer scheduledTimerWithTimeInterval:scrollTimeInterval target:self selector:@selector(run) userInfo:nil repeats:YES];


}

当run方法被触发时。默认用户没有拖拽。isUserDragged =NO;

-(void)run{


            isUserDragged =NO;

        pageIndex++;

        UIButton *button =(UIButton *)[self viewWithTag:(100+pageIndex)];
        [self pageIndicatorClicked:button];

        if (pageIndex==[dataArr count]) {
            pageIndex=0;


        }


    NSLog(@"**pageIndex******%d*********",(int)pageIndex);


}

这种话,事实上有两种模式,定时器轮播,用户手动切换页面。


以下来看看动画效果吧
技术分享

demo下载地址例如以下:
demo

自己封装的轮播工具

标签:count   ring   动画效果   .net   offset   span   function   分析   sch   

原文地址:http://www.cnblogs.com/jhcelue/p/7047619.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!