探探 和 陌陌 都有git
如今比較流行的社交軟件都有這麼一個功能模塊,喜歡←劃,不喜歡→劃, 多麼經典的一個廣告語啊。
我就在業餘時間寫了這麼一個demo樣例github
這兩個都是比較參數經典的案例ui
//代理 @property (nonatomic, weak) id<TanTanDelegate>delegate; //數據源 @property (nonatomic, weak) id<TanTanDataSource>dataSource; //是否設置循環 @property (nonatomic, assign) BOOL isCyclically; //展現出來的item數目 @property (nonatomic, assign) NSInteger showItemsNumber; //設置偏移量 @property (nonatomic, assign) CGSize offSet; //顯示的第一個View @property (nonatomic, strong , readonly) UIView *topView; //刷新展現數據 - (void)refreshData;
咱們能夠經過設置isCyclically來實現視圖是否循環,經過offset來設置重疊視圖的重疊方向 `atom
@protocol TanTanDataSource <NSObject> @required - (NSInteger)numberOfItemInTanTan:(TanTanView *)tantan; - (UIView *)tantan:(TanTanView *)tantan viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view; @end
上面的這個是數據源,這兩個方法的思路和UITableView的數據源差很少,一個是設置數據源數目,一個就是視圖複用spa
@protocol TanTanDelegate <NSObject> @optional - (void)tantan:(TanTanView *)tantan beforeSwipingItemAtIndex:(NSInteger)index; - (void)tantan:(TanTanView *)tantan didRemovedItemAtIndex:(NSInteger)index; - (void)tantan:(TanTanView *)tantan didLeftRemovedItemAtIndex:(NSInteger)index; - (void)tantan:(TanTanView *)tantan didRightRemovedItemAtIndex:(NSInteger)index;
這就是相應的代理方法代理
github:https://github.com/cAibDe/TanTancode