| | |
| | | var interval:Double = 3 |
| | | |
| | | private var startOffsetX:CGFloat = 0 |
| | | private var fillBounds:CGRect? |
| | | |
| | | override func layoutSubviews() { |
| | | super.layoutSubviews() |
| | | } |
| | | |
| | | public func setImages(images:Array<String>,type:ImageType |
| | | = .Image,imageClickBlock:@escaping (Int) -> Void) { |
| | | = .Image,fillBounds:CGRect? = nil,imageClickBlock:@escaping (Int) -> Void) { |
| | | self.type = type |
| | | self.fillBounds = fillBounds |
| | | self.images = images |
| | | self.clickBlock = imageClickBlock |
| | | self.initLayout() |
| | |
| | | return |
| | | } |
| | | |
| | | width = self.bounds.width |
| | | height = self.bounds.height |
| | | if fillBounds != nil{ |
| | | width = fillBounds!.width |
| | | height = fillBounds!.height |
| | | scrollView.frame = CGRect(origin: .zero, size: fillBounds!.size) |
| | | }else{ |
| | | width = self.bounds.width |
| | | height = self.bounds.height |
| | | scrollView.frame = self.bounds |
| | | } |
| | | |
| | | scrollView.frame = self.bounds |
| | | scrollView.contentSize = CGSize(width:width * CGFloat(images.count + |
| | | 2),height:height) |
| | | scrollView.contentOffset = CGPoint(x:width,y:0) |
| | | scrollView.isUserInteractionEnabled = true |
| | | scrollView.isPagingEnabled = true |
| | | scrollView.isScrollEnabled = images.count > 1 |
| | | scrollView.contentInsetAdjustmentBehavior = .never |
| | | scrollView.showsHorizontalScrollIndicator = false |
| | | scrollView.delegate = self |
| | | self.addSubview(scrollView) |
| | |
| | | } |
| | | } |
| | | |
| | | func setCurrent(currIndex:Int) { |
| | | func setCurrent(currIndex:Int,animate:Bool = false) { |
| | | if(currIndex < 0){ |
| | | self.currIndex = images.count - 1 |
| | | }else{ |
| | | self.currIndex = currIndex |
| | | } |
| | | pageControl.currentPage = self.currIndex |
| | | scrollView.setContentOffset(CGPoint(x:width * CGFloat(self.currIndex + |
| | | 1),y:0), animated: false) |
| | | |
| | | if animate{ |
| | | scrollView.setContentOffset(CGPoint(x:width * CGFloat(self.currIndex + 1),y:0), animated: false) |
| | | } |
| | | } |
| | | |
| | | //给图⽚添加点击⼿势 |
| | |
| | | |
| | | @objc func startAutoScroll(){ |
| | | if(isDisplayInScreen()){ |
| | | setCurrent(currIndex: (currIndex + 1) % images.count) |
| | | setCurrent(currIndex: (currIndex + 1) % images.count,animate: true) |
| | | } |
| | | } |
| | | |