UUMarqueeView.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // UUMarqueeView.h
  3. // UUMarqueeView
  4. //
  5. // Created by youyou on 16/12/5.
  6. // Copyright © 2016年 iceyouyou. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. @class UUMarqueeView;
  10. typedef NS_ENUM(NSUInteger, UUMarqueeViewDirection) {
  11. UUMarqueeViewDirectionUpward, // scroll from bottom to top
  12. UUMarqueeViewDirectionLeftward // scroll from right to left
  13. };
  14. #pragma mark - UUMarqueeViewDelegate
  15. @protocol UUMarqueeViewDelegate <NSObject>
  16. - (NSUInteger)numberOfDataForMarqueeView:(UUMarqueeView*)marqueeView;
  17. - (void)createItemView:(UIView*)itemView forMarqueeView:(UUMarqueeView*)marqueeView;
  18. - (void)updateItemView:(UIView*)itemView atIndex:(NSUInteger)index forMarqueeView:(UUMarqueeView*)marqueeView;
  19. @optional
  20. - (NSUInteger)numberOfVisibleItemsForMarqueeView:(UUMarqueeView*)marqueeView; // only for [UUMarqueeViewDirectionUpward]
  21. - (CGFloat)itemViewWidthAtIndex:(NSUInteger)index forMarqueeView:(UUMarqueeView*)marqueeView; // only for [UUMarqueeViewDirectionLeftward]
  22. - (CGFloat)itemViewHeightAtIndex:(NSUInteger)index forMarqueeView:(UUMarqueeView*)marqueeView; // only for [UUMarqueeViewDirectionUpward] and [useDynamicHeight = YES]
  23. - (void)didTouchItemViewAtIndex:(NSUInteger)index forMarqueeView:(UUMarqueeView*)marqueeView;
  24. @end
  25. #pragma mark - UUMarqueeView
  26. @interface UUMarqueeView : UIView
  27. @property (nonatomic, weak) id<UUMarqueeViewDelegate> delegate;
  28. @property (nonatomic, assign) NSTimeInterval timeIntervalPerScroll;
  29. @property (nonatomic, assign) NSTimeInterval timeDurationPerScroll; // only for [UUMarqueeViewDirectionUpward] and [useDynamicHeight = NO]
  30. @property (nonatomic, assign) BOOL useDynamicHeight; // only for [UUMarqueeViewDirectionUpward]
  31. @property (nonatomic, assign) float scrollSpeed; // only for [UUMarqueeViewDirectionLeftward] or [UUMarqueeViewDirectionUpward] with [useDynamicHeight = YES]
  32. @property (nonatomic, assign) float itemSpacing; // only for [UUMarqueeViewDirectionLeftward]
  33. @property (nonatomic, assign) BOOL stopWhenLessData; // do not scroll when all data has been shown
  34. @property (nonatomic, assign) BOOL clipsToBounds;
  35. @property (nonatomic, assign, getter=isTouchEnabled) BOOL touchEnabled;
  36. @property (nonatomic, assign) UUMarqueeViewDirection direction;
  37. - (instancetype)initWithDirection:(UUMarqueeViewDirection)direction;
  38. - (instancetype)initWithFrame:(CGRect)frame direction:(UUMarqueeViewDirection)direction;
  39. - (void)reloadData;
  40. - (void)start;
  41. - (void)pause;
  42. @end
  43. #pragma mark - UUMarqueeViewTouchResponder(Private)
  44. @protocol UUMarqueeViewTouchResponder <NSObject>
  45. - (void)touchesBegan;
  46. - (void)touchesEndedAtPoint:(CGPoint)point;
  47. - (void)touchesCancelled;
  48. @end
  49. #pragma mark - UUMarqueeViewTouchReceiver(Private)
  50. @interface UUMarqueeViewTouchReceiver : UIView
  51. @property (nonatomic, weak) id<UUMarqueeViewTouchResponder> touchDelegate;
  52. @end
  53. #pragma mark - UUMarqueeItemView(Private)
  54. @interface UUMarqueeItemView : UIView // UUMarqueeItemView's [tag] is the index of data source. if none data source then [tag] is -1
  55. @property (nonatomic, assign) BOOL didFinishCreate;
  56. @property (nonatomic, assign) CGFloat width; // cache the item width, only for [UUMarqueeViewDirectionLeftward]
  57. @property (nonatomic, assign) CGFloat height; // cache the item height, only for [UUMarqueeViewDirectionUpward]
  58. - (void)clear;
  59. @end