这是一个易于使用的 UITableViewCell 子类,实现了一个带有媒体内容的滚动效果单元格,如图像、视频、声音等...
要运行示例项目;请克隆仓库,然后首先从项目目录运行 pod install。
导入类 #import "SAScrollTableViewCell.h"
并添加其代理 SAScrollTableViewCellDelegate
。
在 init 或 viewDidLoad 方法中注册类 [self.tableView registerClass:[SAScrollTableViewCell class] forCellReuseIdentifier:@"Cell"];
。在 heightForRowAtIndexPath 中设置单元格的高度为 140。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *const cellIdentifier = @"Cell";
SAScrollTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[SAScrollTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.delegate = self;
[cell setMedia:@[
[SAScrollMedia mediaWithType:SAMediaTypeVideoAsset
title:@"title"
object:[[NSBundle mainBundle] URLForResource:@"sample1" withExtension:@"mov"]],
[SAScrollMedia mediaWithType:SAScrollMediaTypeImageName title:@"title" object:@"sample1.jpg"],
[SAScrollMedia mediaWithType:SAScrollMediaTypeImageName title:@"title" object:@"sample2.jpg"],
[SAScrollMedia mediaWithType:SAScrollMediaTypeImageName title:@"title" object:@"sample3.jpg"]
]];
return cell;
}
SAScrollTableViewCell
预期使用 SAScrollMedia
,它包含每个媒体内容,如图像、视频和声音。使用工厂方法创建对象 mediaWithType:(SAScrollMediaType)type title:(NSString *)title object:(id)object;
。目前只支持四种媒体类型,使用以下键:
typedef NS_ENUM(NSUInteger, SAScrollMediaType) {
/**
* UIImage object
*/
SAScrollMediaTypeImageObject,
/**
* name of a file within main bundle i.e sample1.png
*/
SAScrollMediaTypeImageName,
/**
* NSData of a image
*/
SAScrollMediaTypeRawImage,
/**
* NSURL of a link to a video file supported by iOS
*/
SAScrollMediaTypeVideoAsset,
/**
* NSURL link of image on the web i.e http://lorempixel.com/250/250/
*/
SAScrollMediaTypeImageURL
/**
* for subclassing
*/
SAScrollMediaTypeOther
};
iOS 7,仅支持横屏
shams ahmed,[email protected]
SAScrollTableViewCell 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。