Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
maltsugar committed Apr 15, 2020
1 parent f48e5da commit d5bb1ed
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#### (for Swfit 4.2+)

### 版本记录
- 1.1.0 修复[#16](https://github.com/maltsugar/RollingNotice/issues/16)[#17](https://github.com/maltsugar/RollingNotice/issues/17),感谢[@xygkevin][https://github.com/xygkevin]
- 1.0.9 新增暂停/恢复功能
- 1.0.8 修复[#4](https://github.com/maltsugar/RollingNotice-Swift/issues/4)数据源返回数量为0时,不再显示cell,感谢建议
- 1.0.7 普通用法textLabel支持左右间距设置
Expand Down
2 changes: 1 addition & 1 deletion RollingNotice-Swift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "RollingNotice-Swift"
s.version = "1.0.9"
s.version = "1.1.0"
s.summary = "滚动公告、广告,支持灵活自定义cell。淘宝、口碑、京东、美团、天猫等等一切滚动广告 Roll Notice or Advertising. A rolling banner, custom cell like UITableViewCell supported"

# This description is used to generate tags and improve search results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,20 @@ open class GYRollingNoticeView: UIView {
weak open var dataSource : GYRollingNoticeViewDataSource?
weak open var delegate : GYRollingNoticeViewDelegate?
open var stayInterval = 2.0
open private(set) var currentIndex = 0
open private(set) var status: GYRollingNoticeViewStatus = .idle
open var currentIndex: Int {
guard let count = (self.dataSource?.numberOfRowsFor(roolingView: self)) else { return 0}

if (_cIdx > count - 1) {
_cIdx = 0
}
return _cIdx;
}


private var _cIdx = 0
private var _needTryRoll = false


// MARK: private properties
private lazy var cellClsDict: Dictionary = { () -> [String : Any] in
Expand Down Expand Up @@ -110,7 +122,7 @@ open class GYRollingNoticeView: UIView {

status = .idle
isAnimating = false
currentIndex = 0
_cIdx = 0
currentCell?.removeFromSuperview()
willShowCell?.removeFromSuperview()
currentCell = nil
Expand Down Expand Up @@ -145,6 +157,13 @@ open class GYRollingNoticeView: UIView {

override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
}
open override func layoutSubviews() {
super.layoutSubviews()
if (_needTryRoll) {
self.reloadDataAndStartRoll()
_needTryRoll = false
}
}

}

Expand All @@ -156,7 +175,7 @@ extension GYRollingNoticeView{
return
}
layoutCurrentCellAndWillShowCell()
currentIndex += 1


let w = self.frame.size.width
let h = self.frame.size.height
Expand All @@ -172,32 +191,38 @@ extension GYRollingNoticeView{
self.currentCell = cell1
}
self.isAnimating = false
self._cIdx += 1
}
}


fileprivate func layoutCurrentCellAndWillShowCell() {
guard let count = (self.dataSource?.numberOfRowsFor(roolingView: self)) else { return }

if (currentIndex > count - 1) {
currentIndex = 0
if (_cIdx > count - 1) {
_cIdx = 0
}

var willShowIndex = currentIndex + 1
var willShowIndex = _cIdx + 1
if (willShowIndex > count - 1) {
willShowIndex = 0
}
// print(">>>>%d", currentIndex)
// print(">>>>%d", _cIdx)

let w = self.frame.size.width
let h = self.frame.size.height

// print("count: \(count), currentIndex:\(currentIndex) willShowIndex: \(willShowIndex)")
// print("count: \(count), _cIdx:\(_cIdx) willShowIndex: \(willShowIndex)")

if !(w > 0 && h > 0) {
_needTryRoll = true
return
}

if currentCell == nil {
// 第一次没有currentcell
// currentcell is null at first time
if let cell = self.dataSource?.rollingNoticeView(roolingView: self, cellAtIndex: currentIndex) {
if let cell = self.dataSource?.rollingNoticeView(roolingView: self, cellAtIndex: _cIdx) {
currentCell = cell
cell.frame = CGRect(x: 0, y: 0, width: w, height: h)
self.addSubview(cell)
Expand Down Expand Up @@ -237,14 +262,7 @@ extension GYRollingNoticeView{
}

@objc fileprivate func handleCellTapAction(){
guard let count = self.dataSource?.numberOfRowsFor(roolingView: self) else {
return
}

if (currentIndex > count - 1) {
currentIndex = 0;
}
self.delegate?.rollingNoticeView?(self, didClickAt: currentIndex)
self.delegate?.rollingNoticeView?(self, didClickAt: self.currentIndex)
}

fileprivate func setupNoticeViews() {
Expand Down

0 comments on commit d5bb1ed

Please sign in to comment.