ImageSlidesShowView.swift 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // ImageSlidesShowView.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2017/3/12.
  6. // Copyright © 2017年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import ImageSlideshow
  10. import Alamofire
  11. import AlamofireImage
  12. import AlamofireObjectMapper
  13. import ObjectMapper
  14. import CocoaLumberjack
  15. protocol ImageSlidesShowViewDelegate {
  16. func ImageSlidesShowClick(taskImageshowEntity: TaskImageshowEntity)
  17. }
  18. class ImageSlidesShowView: UIView {
  19. private lazy var imageSlideshow: ImageSlideshow = ImageSlideshow()
  20. var delegate: ImageSlidesShowViewDelegate?
  21. var imageshowEntitys: [TaskImageshowEntity] = [] {
  22. didSet {
  23. self.imageURLS.removeAll(keepingCapacity: true)
  24. imageshowEntitys.forEach { (taskImageshowEntity) in
  25. let imageURL = AppDelegate.o2Collect.generateURLWithAppContextKey(FileContext.fileContextKey, query: FileContext.fileDownloadNoStreamIdQuery, parameter: ["##id##": taskImageshowEntity.picId as AnyObject])
  26. DDLogDebug("hot image url : \(String(describing: imageURL))")
  27. let afurl = O2AlamofireSource(urlString: imageURL!)
  28. self.imageURLS.append(afurl!)
  29. }
  30. imageSlideshow.setImageInputs(imageURLS)
  31. }
  32. }
  33. fileprivate var imageURLS: [O2AlamofireSource] = []
  34. override init(frame: CGRect) {
  35. super.init(frame: frame)
  36. self.imageSlideshow.frame = CGRect(x: 0, y: 0, width: frame.width, height: frame.height)
  37. self.imageSlideshow.backgroundColor = UIColor.white
  38. self.imageSlideshow.slideshowInterval = 6.0
  39. self.imageSlideshow.preload = .all
  40. self.imageSlideshow.pageControlPosition = PageControlPosition.insideScrollView
  41. self.imageSlideshow.pageControl.currentPageIndicatorTintColor = navbar_barTint_color
  42. self.imageSlideshow.pageControl.pageIndicatorTintColor = UIColor.lightGray
  43. self.imageSlideshow.contentScaleMode = UIView.ContentMode.scaleToFill
  44. self.imageSlideshow.addTapGesture(target: self, action: #selector(imageSlideshowClick(sender:)))
  45. self.addSubview(self.imageSlideshow)
  46. }
  47. required init?(coder aDecoder: NSCoder) {
  48. fatalError("init(coder:) has not been implemented")
  49. }
  50. @objc public func imageSlideshowClick(sender: ImageSlideshow?) {
  51. //print(self.imageSlideshow.currentPage)
  52. if delegate != nil {
  53. let entity = self.imageshowEntitys[self.imageSlideshow.currentPage]
  54. self.delegate?.ImageSlidesShowClick(taskImageshowEntity: entity)
  55. }
  56. }
  57. }