代码库> 列表> IDNLoopView 图片/视图循环播放控件(可在Touch过程中改变控件大小)
IDNLoopView 图片/视图循环播放控件(可在Touch过程中改变控件大小)
关注
查看次数:2150 下载次数:197
上传时间:2015-07-06 大小:465 B
cvpic('https://github.com/photondragon/IDNLoopView/raw/master/IDNLoopView.gif','','700','700')

在github上的地址 https://github.com/photondragon/IDNLoopView

这个控件有如下特点:

1. 可实现图片或视图的无限循环播放
2. 支持任意类型视图,包括但不限于UIImageView
3. 可在Touch过程中改变控件大小,过渡效果完美
4. 可配合SDWebImage流畅加载网络图片
5. 当Touch时,自动播放定时器会重置
6. 使用方法类似UITableView,没有学习成本

使用方法

先将源文件`IDNLoopView.h`和`IDNLoopView.m`加入项目中,具体用法跟UITableView差不多,示例代码如下:


#import "ViewController.h"
#import "IDNLoopView.h"

@interface ViewController ()
IDNLoopViewDataSource>

@property (weak, nonatomic) IBOutlet IDNLoopView *loopView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.loopView.datasource = self;
    self.loopView.delegate = self;
//    self.loopView.reuseDisabled = YES; //关闭view回收机制
//    self.loopView.pageControl.hidden = YES; //隐藏内置的UIPageControl
//    self.loopView.intervalTime = 0; //关闭自动切换
//    self.loopView.currentIndex = 2;
}

#pragma mark IDNLoopView DataSource & Delegate

- (NSInteger)numberOfViewsInLoopView:(IDNLoopView *)loopView
{
    return 6;
}

- (UIView*)loopView:(IDNLoopView *)loopView viewAtIndex:(NSInteger)index reuseView:(UIView *)view
{
    UIImageView* imageView;
    if(view==nil)
    {
        imageView = [[UIImageView alloc] init];
    }
    else
        imageView = (UIImageView*)view;
    
    NSString* imgfile = [NSString stringWithFormat:@"抽象派艺术%03d.jpg", (int)index];
    NSLog(@"%@", imgfile);
    imageView.image = [UIImage imageNamed:imgfile];
    
    return imageView;
}

- (void)loopView:(IDNLoopView *)loopView didTapViewAtIndex:(NSInteger)index
{
    NSLog(@"tap index = %d", (int)index);
}

- (void)loopView:(IDNLoopView *)loopView didShowViewAtIndex:(NSInteger)index
{
    NSLog(@"current index = %d", (int)index);
}

@end


如果要显示网络图片,可配合SDWebImage使用,修改数据源方法`- loopView:viewAtIndex:reuseView:`如下:


- (UIView*)loopView:(IDNLoopView *)loopView viewAtIndex:(NSInteger)index reuseView:(UIView *)view
{
    UIImageView* imageView;
    if(view==nil)
    {
        imageView = [[UIImageView alloc] init];
    }
    else
        imageView = (UIImageView*)view;

    static UIImage* placeholder = nil;
    if(placeholder==nil)
        placeholder = [UIImage imageNamed:@"imageLoading.jpg"];
        
    [imageView sd_setImageWithURL:[NSURL URLWithString:self.images[index]] placeholderImage:placeholder];

    return imageView;
}
收藏
我来说两句
发表评论
您还没有登录!请登录注册
所有评论(0
提示
sina mail 回到顶部