悟空记账

ELTransitionBannerView.m 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. //
  2. // ELTransitionBannerView.m
  3. // demo111
  4. //
  5. // Created by 费宇超 on 2018/2/2.
  6. // Copyright © 2018年 费宇超. All rights reserved.
  7. //
  8. #import "ELTransitionBannerView.h"
  9. #import "ELTransitionView.h"
  10. #import <SDWebImage/SDWebImagePrefetcher.h>
  11. #import <SDWebImage/UIImageView+WebCache.h>
  12. //判断方向 区别于velocity瞬时速度的方向
  13. typedef NS_ENUM(NSInteger, ELTransitionBannerViewDirection) {
  14. ELTransitionBannerViewDirectionUnknow,
  15. ELTransitionBannerViewDirectionLeft,
  16. ELTransitionBannerViewDirectionRight
  17. };
  18. @interface ELTransitionBannerView()<UIGestureRecognizerDelegate>
  19. @property (nonatomic, strong) UIImageView * vImageBottom;
  20. @property (nonatomic, strong) UIView * vClipView;
  21. @property (nonatomic, strong) UIImageView * vImageTop;
  22. @property (nonatomic, strong) UIView * vMask;
  23. @property (nonatomic, strong) ELTransitionView * vTransitionLeft;
  24. @property (nonatomic, strong) ELTransitionView * vTransitionRight;
  25. @property (nonatomic, strong) UIPanGestureRecognizer *panGesture;
  26. @property (nonatomic, strong) UITapGestureRecognizer *tap;
  27. /** 滚动方向 */
  28. @property (nonatomic, assign) ELTransitionBannerViewDirection direction;
  29. @property (nonatomic, assign) BOOL isResetDirection;
  30. @property (nonatomic, assign) CGFloat firstPoint;
  31. @property (nonatomic, assign) NSInteger currentPage;
  32. @property (nonatomic, assign) NSInteger TotalPage;
  33. @property (nonatomic, strong) NSTimer *timer;
  34. //配饰
  35. @property (nonatomic, strong) UIImageView * vFragranceTop1;
  36. @property (nonatomic, strong) UIImageView * vFragranceTop2;
  37. @property (nonatomic, strong) UIImageView * vFragranceBottom;
  38. //banner的高度不包括配饰
  39. @property (nonatomic, assign) CGFloat bannerHeight;
  40. @property (nonatomic, assign) CGFloat bannerWidth;
  41. @end
  42. @implementation ELTransitionBannerView
  43. - (instancetype)initWithFrame:(CGRect)frame {
  44. if (self = [super initWithFrame:frame]) {
  45. self.bannerHeight = frame.size.height - 36;
  46. self.bannerWidth = frame.size.width - 10;
  47. // self.placeholderImage = [UIImage imageFromBundle:@"learning_background_placeholder"];
  48. [self setUI];
  49. [self setNotifications];
  50. }
  51. return self;
  52. }
  53. - (void)setNotifications {
  54. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(elBannerStartRolling) name:UIApplicationDidBecomeActiveNotification object:nil];
  55. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(elBannerStopRolling) name:UIApplicationDidEnterBackgroundNotification object:nil];
  56. }
  57. - (void)dealloc {
  58. NSLog(@"%s",__func__);
  59. [[NSNotificationCenter defaultCenter] removeObserver:self];
  60. }
  61. - (void)setUI{
  62. self.rollInterval = 5;
  63. self.isResetDirection = YES;
  64. [self addSubview:self.vClipView];
  65. [self.vClipView addSubview:self.vImageBottom];
  66. [self.vClipView addSubview:self.vImageTop];
  67. [self addSubview:self.vFragranceTop1];
  68. [self addSubview:self.vFragranceBottom];
  69. //把top的交互事件关闭 所有的pan和点击都交给下一个视图
  70. self.vImageTop.userInteractionEnabled = NO;
  71. self.vImageBottom.userInteractionEnabled = YES;
  72. self.tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPageView)];
  73. [self.vImageBottom addGestureRecognizer:self.panGesture];
  74. [self.vImageBottom addGestureRecognizer:self.tap];
  75. self.vImageTop.maskView = self.vMask;
  76. }
  77. #pragma mark - UIPanDelegate Methods
  78. - (void)panOnBanner:(UIPanGestureRecognizer *)recognizer
  79. {
  80. CGPoint translatedPoint = [recognizer translationInView:self];
  81. if ([recognizer state] == UIGestureRecognizerStateBegan) {
  82. [self elBannerStopRolling];
  83. self.firstPoint = translatedPoint.x;
  84. }else if ([recognizer state] == UIGestureRecognizerStateChanged){
  85. [self elBannerStopRolling];
  86. if (self.isResetDirection == YES) {
  87. if (translatedPoint.x > self.firstPoint) {
  88. self.direction = ELTransitionBannerViewDirectionRight;
  89. self.isResetDirection = NO;
  90. }else if (translatedPoint.x < self.firstPoint) {
  91. self.direction = ELTransitionBannerViewDirectionLeft;
  92. self.isResetDirection = NO;
  93. }
  94. }else{
  95. //
  96. }
  97. switch (self.direction) {
  98. case ELTransitionBannerViewDirectionRight:
  99. {
  100. NSInteger LastPage;
  101. if (self.currentPage == 0) {
  102. LastPage = self.TotalPage;
  103. }else{
  104. LastPage = self.currentPage - 1;
  105. }
  106. [self.vImageTop sd_setImageWithURL:[NSURL URLWithString:[self.imageURLs objectAtIndex:LastPage]] placeholderImage:self.placeholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  107. if (image) {
  108. self.vImageTop.image = image;
  109. }else{
  110. self.vImageTop.image = self.placeholderImage;
  111. }
  112. }];
  113. }
  114. if (fabs(translatedPoint.x)>10) {
  115. CGRect rect = self.vImageBottom.frame;
  116. rect.origin.x = fabs(translatedPoint.x/self.bannerWidth)*50;
  117. self.vImageBottom.frame =rect;
  118. }
  119. self.vTransitionLeft.frame = CGRectMake(fabs(translatedPoint.x *1.3)+-self.bannerWidth-120, 0, self.bannerWidth + 120, self.bannerHeight);
  120. break;
  121. case ELTransitionBannerViewDirectionLeft:
  122. {
  123. NSInteger nextPage;
  124. if (self.currentPage == self.TotalPage) {
  125. nextPage = 0;
  126. }else{
  127. nextPage = self.currentPage + 1;
  128. }
  129. [self.vImageTop sd_setImageWithURL:[NSURL URLWithString:[self.imageURLs objectAtIndex:nextPage]] placeholderImage:self.placeholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  130. if (image) {
  131. self.vImageTop.image = image;
  132. }else{
  133. self.vImageTop.image = self.placeholderImage;
  134. }
  135. }];
  136. }
  137. self.vTransitionRight.frame = CGRectMake(self.bannerWidth + translatedPoint.x *1.3, 0, self.bannerWidth + 120, self.bannerHeight);
  138. if (fabs(translatedPoint.x)>10) {
  139. CGRect rect = self.vImageBottom.frame;
  140. rect.origin.x = - fabs(translatedPoint.x/self.bannerWidth)*50;
  141. self.vImageBottom.frame =rect;
  142. }
  143. break;
  144. default:
  145. break;
  146. }
  147. }else if ([recognizer state] == UIGestureRecognizerStateEnded){
  148. //偏移量不足翻页 根据速度判断是否要翻页
  149. if (fabs(translatedPoint.x-self.firstPoint) < self.bannerWidth/2) {
  150. CGPoint speed = [recognizer velocityInView:recognizer.view];
  151. if (fabs(speed.x) > 800) {
  152. switch (self.direction) {
  153. case ELTransitionBannerViewDirectionLeft:
  154. {
  155. if (speed.x<0) {
  156. [self TransitionTwoImageViewWithDirection:self.vTransitionRight WithInterVal:0.3];
  157. }else{
  158. [self resetMaskViewFrame];
  159. }
  160. }
  161. break;
  162. case ELTransitionBannerViewDirectionRight:
  163. {
  164. if (speed.x>0) {
  165. [self TransitionTwoImageViewWithDirection:self.vTransitionLeft WithInterVal:0.3];
  166. }else{
  167. [self resetMaskViewFrame];
  168. }
  169. break;
  170. }
  171. default:
  172. break;
  173. }
  174. }else{
  175. [self resetMaskViewFrame];
  176. }
  177. }else{
  178. if (self.direction == ELTransitionBannerViewDirectionRight) {
  179. [self TransitionTwoImageViewWithDirection:self.vTransitionLeft WithInterVal:0.5];
  180. }else if (self.direction == ELTransitionBannerViewDirectionLeft){
  181. [self TransitionTwoImageViewWithDirection:self.vTransitionRight WithInterVal:0.5];
  182. }
  183. }
  184. [self elBannerStartRolling];
  185. self.isResetDirection = YES;
  186. }else if ([recognizer state] == UIGestureRecognizerStateCancelled){
  187. }
  188. }
  189. - (void)tapPageView{
  190. if ([self.delegate respondsToSelector:@selector(bannerView:didClickAtIndex:)]) {
  191. [self.delegate bannerView:self didClickAtIndex:self.currentPage];
  192. NSLog(@"里面点击的是哪一个呢++%ld",(long)self.currentPage);
  193. }
  194. }
  195. #pragma mark - Public Methods
  196. - (void)elBannerStopRolling{
  197. if (_timer) {
  198. [_timer invalidate];
  199. _timer = nil;
  200. }
  201. }
  202. - (void)resetRolling {
  203. [self elBannerStopRolling];
  204. [self elBannerStartRolling];
  205. }
  206. - (void)elBannerStartRolling{
  207. if (self.imageURLs.count <= 1) {
  208. return;
  209. }
  210. [self.timer setFireDate:[NSDate dateWithTimeInterval:self.rollInterval sinceDate:[NSDate date]]];
  211. }
  212. // 参数要细调
  213. - (void)shakeAim{
  214. self.hidden = NO;
  215. CGPoint oldOrigin = self.frame.origin;
  216. self.layer.anchorPoint = CGPointMake(0.5, 0);
  217. CGPoint newOrigin = self.frame.origin;
  218. CGPoint transition;
  219. transition.x = newOrigin.x - oldOrigin.x;
  220. transition.y = newOrigin.y - oldOrigin.y;
  221. self.center = CGPointMake (self.center.x - transition.x, self.center.y - transition.y);
  222. self.transform = CGAffineTransformMakeRotation(M_PI * - 0.2);
  223. //尽可能地去模仿物理学 交替使用in out //可以用阻尼系数做 但UI不是这个效果,可以优化成关键帧
  224. [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
  225. self.alpha = 1;
  226. self.transform = CGAffineTransformMakeRotation(M_PI * 0);
  227. } completion:^(BOOL finished) {
  228. [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
  229. self.transform = CGAffineTransformMakeRotation(M_PI * 0.08);
  230. } completion:^(BOOL finished) {
  231. [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
  232. self.transform = CGAffineTransformMakeRotation(M_PI * 0);
  233. } completion:^(BOOL finished) {
  234. [UIView animateWithDuration:0.16 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
  235. self.transform = CGAffineTransformMakeRotation(M_PI * - 0.04);
  236. } completion:^(BOOL finished) {
  237. [UIView animateWithDuration:0.16 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
  238. self.transform = CGAffineTransformMakeRotation(M_PI * 0);
  239. } completion:^(BOOL finished) {
  240. [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
  241. self.transform = CGAffineTransformMakeRotation(M_PI * 0.01);
  242. } completion:^(BOOL finished) {
  243. [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
  244. self.transform = CGAffineTransformMakeRotation(M_PI * -0.005);
  245. } completion:^(BOOL finished) {
  246. [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
  247. self.transform = CGAffineTransformMakeRotation(M_PI * 0.0);
  248. } completion:^(BOOL finished) {
  249. }];
  250. }];
  251. }];
  252. }];
  253. }];
  254. }];
  255. }];
  256. }];
  257. }
  258. #pragma mark - private Methods
  259. - (void)prefetchImageWithURLs:(NSArray<NSString *> *)URLs {
  260. NSMutableArray<NSURL *> *marrURL = [NSMutableArray arrayWithCapacity:URLs.count];
  261. for (NSString *URLStr in URLs) {
  262. NSURL *slimURL = [NSURL URLWithString:URLStr];
  263. if (slimURL) {
  264. [marrURL addObject:slimURL];
  265. }
  266. }
  267. [[SDWebImagePrefetcher sharedImagePrefetcher] prefetchURLs:marrURL];
  268. }
  269. - (void)reloadData {
  270. // 预加载图片
  271. self.currentPage = 0;
  272. [self prefetchImageWithURLs:self.imageURLs];
  273. if (!self.superview) {
  274. return;
  275. }
  276. [self configureImages];
  277. [self configureTimer];
  278. }
  279. - (void)configureImages {
  280. [self.vImageBottom sd_setImageWithURL:[NSURL URLWithString:self.imageURLs.firstObject] placeholderImage:self.placeholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  281. if (image) {
  282. self.vImageBottom.image = image;
  283. }else{
  284. self.vImageBottom.image = self.placeholderImage;
  285. }
  286. }];
  287. if (self.imageURLs.count <= 1) {
  288. self.vImageTop.frame = CGRectZero;
  289. } else {
  290. [self.vImageTop sd_setImageWithURL: [NSURL URLWithString:[self.imageURLs objectAtIndex:1]] placeholderImage:self.placeholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  291. if (image) {
  292. self.vImageTop.image = image;
  293. }else{
  294. self.vImageTop.image = self.placeholderImage;
  295. }
  296. }];
  297. }
  298. }
  299. - (void)configureTimer {
  300. if (self.imageURLs.count <= 1) {
  301. [self elBannerStopRolling];
  302. } else {
  303. [self resetRolling];
  304. }
  305. }
  306. - (void)resetMaskViewFrame{
  307. [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
  308. self.vTransitionRight.frame = CGRectMake(self.frame.size.width,0, self.frame.size.width + 120, self.bannerHeight);
  309. self.vTransitionLeft.frame = CGRectMake(-self.frame.size.width-120, 0, self.frame.size.width+120, self.bannerHeight);
  310. self.vImageBottom.frame = CGRectMake(0, 0, self.bannerWidth,self.bannerHeight);
  311. self.userInteractionEnabled = NO;
  312. } completion:^(BOOL finished) {
  313. self.userInteractionEnabled = YES;
  314. }];
  315. }
  316. - (void)doRolling{
  317. [self TransitionTwoImageViewWithDirection:self.vTransitionRight WithInterVal:1];
  318. }
  319. - (void)TransitionTwoImageViewWithDirection:(ELTransitionView *)view WithInterVal:(NSTimeInterval )time{
  320. if ([view isEqual:self.vTransitionLeft]){
  321. NSInteger LastPage;
  322. if (self.currentPage == 0) {
  323. LastPage = self.TotalPage;
  324. }else{
  325. LastPage = self.currentPage - 1;
  326. }
  327. [self.vImageTop sd_setImageWithURL:[NSURL URLWithString:[self.imageURLs objectAtIndex:LastPage]] placeholderImage:self.placeholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  328. if (image) {
  329. self.vImageTop.image = image;
  330. }else{
  331. self.vImageTop.image = self.placeholderImage;
  332. }
  333. }];
  334. }else if ([view isEqual:self.vTransitionRight]) {
  335. NSInteger nextPage;
  336. if (self.currentPage == self.TotalPage) {
  337. nextPage = 0;
  338. }else{
  339. nextPage = self.currentPage + 1;
  340. }
  341. [self.vImageTop sd_setImageWithURL:[NSURL URLWithString:[self.imageURLs objectAtIndex:nextPage]] placeholderImage:self.placeholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  342. if (image) {
  343. self.vImageTop.image = image;
  344. }else{
  345. self.vImageTop.image = self.placeholderImage;
  346. }
  347. }];
  348. }
  349. [UIView animateWithDuration:time delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
  350. if ([view isEqual:self.vTransitionRight]){
  351. CGRect rect = self.vImageBottom.frame;
  352. rect.origin.x = -50;
  353. self.vImageBottom.frame = rect;
  354. }else{
  355. CGRect rect = self.vImageBottom.frame;
  356. rect.origin.x = + 50;
  357. self.vImageBottom.frame = rect;
  358. }
  359. view.frame = CGRectMake(-60, 0, self.frame.size.width + 120, self.bannerHeight);
  360. self.userInteractionEnabled = NO;
  361. } completion:^(BOOL finished) {
  362. if ([view isEqual:self.vTransitionRight]) {
  363. view.frame = CGRectMake(self.frame.size.width, 0, self.frame.size.width+120, self.bannerHeight);
  364. if (self.currentPage == self.TotalPage) {
  365. self.currentPage = 0;
  366. }else{
  367. self.currentPage = self.currentPage + 1;
  368. }
  369. }else if ([view isEqual:self.vTransitionLeft]){
  370. if (self.currentPage == 0) {
  371. self.currentPage = self.TotalPage;
  372. }else{
  373. self.currentPage = self.currentPage - 1;
  374. }
  375. view.frame = CGRectMake(-self.frame.size.width-120, 0, self.frame.size.width+120, self.bannerHeight);
  376. }
  377. if (self.vImageTop.maskView) {
  378. //删除已经出现的视图的mask
  379. self.vImageTop.maskView = nil;
  380. [self.vImageTop.maskView removeFromSuperview];
  381. //交换指针 使得top永远叫top
  382. UIImageView * vTemp = self.vImageTop;
  383. self.vImageTop = self.vImageBottom;
  384. self.vImageBottom = vTemp;
  385. self.vImageTop.frame = CGRectMake(0, 0, self.bannerWidth, self.bannerHeight);
  386. //将下面的图移到上面来
  387. [self.vImageTop removeFromSuperview];
  388. [self.vClipView addSubview:self.vImageTop];
  389. //给上面的视图添加mask
  390. self.vImageTop.maskView = self.vMask;
  391. //把top的交互事件关闭 所有的pan和点击都交给下一个视图
  392. self.userInteractionEnabled = YES;
  393. self.vImageTop.userInteractionEnabled = NO;
  394. [self.vImageTop removeGestureRecognizer:self.panGesture];
  395. [self.vImageTop removeGestureRecognizer:self.tap];
  396. self.vImageBottom.userInteractionEnabled = YES;
  397. [self.vImageBottom addGestureRecognizer:self.panGesture];
  398. [self.vImageBottom addGestureRecognizer:self.tap];
  399. [self bringSubviewToFront:self.vFragranceBottom];
  400. }
  401. }];
  402. }
  403. #pragma mark - Setter Methods
  404. - (NSTimer *)timer {
  405. if (!_timer) {
  406. _timer = [NSTimer scheduledTimerWithTimeInterval:self.rollInterval target:self selector:@selector(doRolling) userInfo:nil repeats:YES];
  407. [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
  408. [_timer setFireDate:[NSDate distantFuture]];
  409. }
  410. return _timer;
  411. }
  412. - (UIImageView *)vImageBottom{
  413. if (!_vImageBottom) {
  414. _vImageBottom = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.bannerWidth, self.bannerHeight)];
  415. // _vImageBottom.image = [UIImage imageFromBundle:@"learning_background_placeholder"];
  416. _vImageBottom.backgroundColor = [UIColor grayColor];
  417. _vImageBottom.contentMode = UIViewContentModeScaleAspectFill;
  418. }
  419. return _vImageBottom;
  420. }
  421. - (UIImageView *)vImageTop{
  422. if (!_vImageTop) {
  423. _vImageTop = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.bannerWidth, self.bannerHeight)];
  424. // _vImageTop.image = [UIImage imageFromBundle:@"learning_background_placeholder"];
  425. _vImageTop.backgroundColor = [UIColor grayColor];
  426. _vImageTop.contentMode = UIViewContentModeScaleAspectFill;
  427. }
  428. return _vImageTop;
  429. }
  430. - (UIImageView *)vFragranceTop1{
  431. if (!_vFragranceTop1) {
  432. _vFragranceTop1 = [[UIImageView alloc]initWithFrame:CGRectMake(-9, 0, self.frame.size.width + 18, 28+10+5)];
  433. _vFragranceTop1.contentMode = UIViewContentModeScaleAspectFit;
  434. _vFragranceTop1.image = [UIImage imageNamed:@"el_banner_Top"];
  435. }
  436. return _vFragranceTop1;
  437. }
  438. - (UIImageView *)vFragranceBottom{
  439. if (!_vFragranceBottom) {
  440. _vFragranceBottom = [[UIImageView alloc]initWithFrame:CGRectMake(0, self.frame.size.height -10, self.frame.size.width, 8)];
  441. _vFragranceBottom.contentMode = UIViewContentModeScaleToFill;
  442. _vFragranceBottom.image = [UIImage imageNamed:@"el_banner_Bottom"];
  443. }
  444. return _vFragranceBottom;
  445. }
  446. - (UIView *)vMask{
  447. if (!_vMask) {
  448. _vMask = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.bannerHeight)];
  449. [_vMask addSubview:self.vTransitionLeft];
  450. [_vMask addSubview:self.vTransitionRight];
  451. }
  452. return _vMask;
  453. }
  454. - (UIView *)vClipView{
  455. if (!_vClipView) {
  456. _vClipView = [[UIView alloc] initWithFrame:CGRectMake(5, 28, self.bannerWidth, self.bannerHeight)];
  457. _vClipView.clipsToBounds = YES;
  458. _vClipView.backgroundColor = [UIColor clearColor];
  459. }
  460. return _vClipView;
  461. }
  462. - (ELTransitionView *)vTransitionLeft{
  463. if (!_vTransitionLeft) {
  464. _vTransitionLeft = [[ELTransitionView alloc] initWithFrame:CGRectMake(-self.frame.size.width-120, 0, self.frame.size.width+120, self.bannerHeight)];
  465. }
  466. return _vTransitionLeft;
  467. }
  468. - (ELTransitionView *)vTransitionRight{
  469. if (!_vTransitionRight) {
  470. _vTransitionRight = [[ELTransitionView alloc] initWithFrame:CGRectMake(self.frame.size.width, 0, self.frame.size.width+120, self.bannerHeight)];
  471. }
  472. return _vTransitionRight;
  473. }
  474. - (UIPanGestureRecognizer *)panGesture{
  475. if (!_panGesture) {
  476. _panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panOnBanner:)];
  477. _panGesture.delegate = self;
  478. [_panGesture setMaximumNumberOfTouches:1];
  479. [_panGesture setDelaysTouchesBegan:YES];
  480. [_panGesture setDelaysTouchesEnded:YES];
  481. [_panGesture setCancelsTouchesInView:YES];
  482. }
  483. return _panGesture;
  484. }
  485. - (void)setImageURLs:(NSArray<NSString *> *)imageURLs {
  486. if (imageURLs.count > 1) {
  487. self.TotalPage = imageURLs.count - 1;
  488. _imageURLs = [imageURLs copy];
  489. [self reloadData];
  490. }else if (imageURLs.count == 0 || imageURLs.count == 1){
  491. _imageURLs = [imageURLs copy];
  492. [self.vImageBottom removeGestureRecognizer:self.panGesture];
  493. [self reloadData];
  494. }
  495. }
  496. @end