ImageSlidesShowView.swift 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. protocol ImageSlidesShowViewDelegate {
  15. func ImageSlidesShowClick(taskImageshowEntity:TaskImageshowEntity)
  16. }
  17. class ImageSlidesShowView: UIView {
  18. private lazy var imageSlideshow:ImageSlideshow = ImageSlideshow()
  19. var delegate:ImageSlidesShowViewDelegate?
  20. var imageshowEntitys:[TaskImageshowEntity] = [] {
  21. didSet {
  22. self.imageURLS.removeAll(keepingCapacity: true)
  23. imageshowEntitys.forEach { (taskImageshowEntity) in
  24. let imageURL = AppDelegate.o2Collect.generateURLWithAppContextKey(FileContext.fileContextKey, query: FileContext.fileDownloadPicItemIdQuery, parameter: ["##id##":taskImageshowEntity.picId as AnyObject])
  25. let afurl = O2AlamofireSource(urlString: imageURL!)
  26. self.imageURLS.append(afurl!)
  27. }
  28. imageSlideshow.setImageInputs(imageURLS)
  29. }
  30. }
  31. fileprivate var imageURLS:[O2AlamofireSource] = []
  32. override init(frame: CGRect) {
  33. super.init(frame: frame)
  34. self.imageSlideshow.frame = CGRect(x: 0, y: 0, width: frame.width, height: frame.height)
  35. self.imageSlideshow.backgroundColor = UIColor.white
  36. self.imageSlideshow.slideshowInterval = 6.0
  37. self.imageSlideshow.preload = .all
  38. self.imageSlideshow.pageControlPosition = PageControlPosition.insideScrollView
  39. self.imageSlideshow.pageControl.currentPageIndicatorTintColor = navbar_barTint_color
  40. self.imageSlideshow.pageControl.pageIndicatorTintColor = UIColor.lightGray
  41. self.imageSlideshow.contentScaleMode = UIView.ContentMode.scaleToFill
  42. self.imageSlideshow.addTapGesture(target: self, action: #selector(imageSlideshowClick(sender:)))
  43. self.addSubview(self.imageSlideshow)
  44. }
  45. required init?(coder aDecoder: NSCoder) {
  46. fatalError("init(coder:) has not been implemented")
  47. }
  48. @objc public func imageSlideshowClick(sender:ImageSlideshow?){
  49. //print(self.imageSlideshow.currentPage)
  50. if delegate != nil{
  51. let entity = self.imageshowEntitys[self.imageSlideshow.currentPage]
  52. self.delegate?.ImageSlidesShowClick(taskImageshowEntity: entity)
  53. }
  54. }
  55. }