Skip to content

Commit

Permalink
新增暂停/恢复功能
Browse files Browse the repository at this point in the history
  • Loading branch information
maltsugar committed Oct 24, 2019
1 parent 8d3678e commit f48e5da
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 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.0.9 新增暂停/恢复功能
- 1.0.8 修复[#4](https://github.com/maltsugar/RollingNotice-Swift/issues/4)数据源返回数量为0时,不再显示cell,感谢建议
- 1.0.7 普通用法textLabel支持左右间距设置
- 1.0.6 demo类支持Swift 5.0
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.8"
s.version = "1.0.9"
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
28 changes: 23 additions & 5 deletions RollingNotice-Swift/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" systemVersion="17A277" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15400" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15404"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="RollingNotice_Swift" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="WAX-bT-j4I"/>
<viewControllerLayoutGuide type="bottom" id="fSb-Js-dP2"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="YMH-d9-NsQ">
<rect key="frame" x="166.5" y="342" width="42" height="30"/>
<state key="normal" title="Pause"/>
<connections>
<action selector="handleBtnAction:" destination="BYZ-38-t0r" eventType="touchUpInside" id="p26-N9-qXI"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<constraints>
<constraint firstItem="fSb-Js-dP2" firstAttribute="top" secondItem="YMH-d9-NsQ" secondAttribute="bottom" constant="295" id="2nF-Gu-3Xc"/>
<constraint firstItem="YMH-d9-NsQ" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="QiV-HL-Y0e"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="132" y="120"/>
</scene>
</scenes>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ import UIKit
@objc optional func rollingNoticeView(_ roolingView: GYRollingNoticeView, didClickAt index: Int)
}


public enum GYRollingNoticeViewStatus: UInt {
case idle, working, pause
}
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

// MARK: private properties
private lazy var cellClsDict: Dictionary = { () -> [String : Any] in
Expand Down Expand Up @@ -93,6 +96,7 @@ open class GYRollingNoticeView: UIView {
if let __timer = timer {
RunLoop.current.add(__timer, forMode: .common)
}
resume()

}

Expand All @@ -104,6 +108,7 @@ open class GYRollingNoticeView: UIView {
timer = nil
}

status = .idle
isAnimating = false
currentIndex = 0
currentCell?.removeFromSuperview()
Expand All @@ -113,6 +118,20 @@ open class GYRollingNoticeView: UIView {
self.reuseCells.removeAll()
}

open func pause() {
if let __timer = timer {
__timer.fireDate = Date.distantFuture
status = .pause
}
}

open func resume() {
if let __timer = timer {
__timer.fireDate = Date.distantPast
status = .working
}
}


override public init(frame: CGRect) {
super.init(frame: frame)
Expand Down
13 changes: 13 additions & 0 deletions RollingNotice-Swift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ class ViewController: UIViewController {



@IBAction func handleBtnAction(_ sender: UIButton) {
guard let notice0 = noticeView0 else {
return
}

if notice0.status == .working {
notice0.pause()
sender.setTitle("Resume", for: .normal)
}else if notice0.status != .working {
notice0.resume()
sender.setTitle("Pause", for: .normal)
}
}


}
Expand Down

0 comments on commit f48e5da

Please sign in to comment.