项目中需要用卡片形式展示商家信息(当然这个展示风景和人物更好),希望左右滑动移除最上面的一张,卡片可以循环显示也可以不循环(即划走的再不见),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
项目中实现卡片式商家信息展示,通过左右滑动移除卡片,使用自定义view iCards,具备循环显示和非循环选择,提供多种控制属性及数据源代理方法,实现了类似iCarousel的效果。源码已开源。

1185

被折叠的 条评论
为什么被折叠?



