您的位置:首页 > 移动开发 > IOS开发

iOS卡片容器iCards

2016-07-21 08:47 330 查看
项目中需要用卡片形式展示商家信息(当然这个展示风景和人物更好),希望左右滑动移除最上面的一张,卡片可以循环显示也可以不循环(即划走的再不见),GitHub上有类似项目,但都耦合在ViewController里,参考其实现封装了一个自定义view,取名iCards(因代理方法参考了第三方库iCarousel, 名称也学习了)。

iCards层叠显示卡片,每张卡片是任意view,你可以通过下边这个代理方法来定义:

- (UIView *)cards:(iCards *)cards viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view;


iCards目前有4个属性,分别控制是否需要循环显示卡片、相邻卡片相对位移、可见的卡片数量(假设你有100张,但可见的可以只有3张)以及是否允许滑动

/** default is YES*/
@property (nonatomic, assign) BOOL itemsShouldShowedCyclically;

/** We will creat this number of views, so not too many; default is 3 */
@property (nonatomic, assign) NSInteger numberOfVisibleItems;

/** offset for the next card to the current card, (it will decide the cards appearance, the top card is on top-left, top, or bottom-right and so on; default is (5, 5) */
@property (nonatomic, assign) CGSize offset;

/** If there is only one card, maybe you don't want to swipe it; */
@property (nonatomic, assign) BOOL swipEnabled;


有两个方法,见名知义,不多说:

- (void)reloadData;
- (UIView *)currentCard;


有两个数据源代理方法:

- (NSInteger)numberOfItemsInCards:(iCards *)cards;
- (UIView *)cards:(iCards *)cards viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view;


4个可选辅助代理方法:

- (void)cards:(iCards *)cards beginSwipingItemAtIndex:(NSInteger)index;
- (void)cards:(iCards *)cards didRemovedItemAtIndex:(NSInteger)index;
- (void)cards:(iCards *)cards didLeftRemovedItemAtIndex:(NSInteger)index;
- (void)cards:(iCards *)cards didRightRemovedItemAtIndex:(NSInteger)index;


以下是效果图:







iCards同样做了Pod支持。源码参见GitHub:iCards
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios cards