Skip to content

Commit

Permalink
Support tvOS
Browse files Browse the repository at this point in the history
  • Loading branch information
WenchaoD committed Feb 22, 2017
1 parent 39b10fb commit 5f16081
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
10 changes: 6 additions & 4 deletions README-OBJECTIVE-C.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# FSPagerView

[![Platform](https://img.shields.io/badge/platform-iOS%207-blue.svg?style=flat)](http://cocoadocs.org/docsets/FSPagerView)
[![Version](https://img.shields.io/cocoapods/v/FSPagerView.svg?style=flat)](http://cocoadocs.org/docsets/FSCalendar) <br/>
[![Languages](https://img.shields.io/badge/language-swift%20|%20objc-FF69B4.svg?style=plastic)](#)
[![Languages](https://img.shields.io/badge/language-swift%20|%20objc-FF69B4.svg?style=plastic)](#) <br/>
[![Platform](https://img.shields.io/badge/platform-iOS%20|%20tvOS-blue.svg?style=plastic)](http://cocoadocs.org/docsets/FSPagerView)
[![Version](https://img.shields.io/cocoapods/v/FSPagerView.svg?style=flat)](http://cocoadocs.org/docsets/FSCalendar)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=plastic)](https://github.com/Carthage/Carthage)
[![SPM compatible](https://img.shields.io/badge/SPM-compatible-FF9966.svg?style=plastic)](https://swift.org/package-manager/)

| [<font size="5"><b>SWIFT</b></font>](https://github.com/WenchaoD/FSPagerView/blob/master/README.md) | <font size="5"><b>OBJECTIVE-C</b></font> |
|[<b>SWIFT</b>](https://github.com/WenchaoD/FSPagerView/blob/master/README.md)|<b>OBJECTIVE-C</b>|
|---|---|

**FSPagerView** is an elegant Screen Slide Library implemented primarily with ***UICollectionView***. It is extremely helpful for making Banner、Product Show、Welcome/Guide Pages、Screen/ViewController Sliders.
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# FSPagerView

[![Languages](https://img.shields.io/badge/language-swift%20|%20objc-FF69B4.svg?style=plastic)](#) <br/>
[![Platform](https://img.shields.io/badge/platform-iOS%207-blue.svg?style=plastic)](http://cocoadocs.org/docsets/FSPagerView)
[![Platform](https://img.shields.io/badge/platform-iOS%20|%20tvOS-blue.svg?style=plastic)](http://cocoadocs.org/docsets/FSPagerView)
[![Version](https://img.shields.io/cocoapods/v/FSPagerView.svg?style=plastic)](http://cocoadocs.org/docsets/FSCalendar)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=plastic)](https://github.com/Carthage/Carthage)
[![SPM compatible](https://img.shields.io/badge/SPM-compatible-FF9966.svg?style=plastic)](https://swift.org/package-manager/)

| <font size="5"><b>SWIFT</b></font> | [<font size="5"><b>OBJECTIVE-C</b></font>](https://github.com/WenchaoD/FSPagerView/blob/master/README-OBJECTIVE-C.md) |
|<b>SWIFT</b>|[<b>OBJECTIVE-C</b>](https://github.com/WenchaoD/FSPagerView/blob/master/README-OBJECTIVE-C.md) |
|---|---|

**FSPagerView** is an elegant Screen Slide Library implemented primarily with ***UICollectionView***. It is extremely helpful for making Banner、Product Show、Welcome/Guide Pages、Screen/ViewController Sliders.
Expand Down
8 changes: 6 additions & 2 deletions Sources/FSPageViewLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class FSPagerViewLayout: UICollectionViewLayout {
}

deinit {
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
#if !os(tvOS)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
#endif
}

override open func prepare() {
Expand Down Expand Up @@ -198,7 +200,9 @@ class FSPagerViewLayout: UICollectionViewLayout {
// MARK:- Private functions

fileprivate func commonInit() {
NotificationCenter.default.addObserver(self, selector: #selector(didReceiveNotification(notification:)), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
#if !os(tvOS)
NotificationCenter.default.addObserver(self, selector: #selector(didReceiveNotification(notification:)), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
#endif
}

fileprivate func adjustCollectionViewBounds() {
Expand Down
10 changes: 7 additions & 3 deletions Sources/FSPagerCollectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class FSPagerViewCollectionView: UICollectionView {
return self.superview?.superview as? FSPagerView
}

#if !os(tvOS)
override var scrollsToTop: Bool {
set {
super.scrollsToTop = false
Expand All @@ -24,6 +25,7 @@ class FSPagerViewCollectionView: UICollectionView {
return false
}
}
#endif

override var contentInset: UIEdgeInsets {
set {
Expand All @@ -47,14 +49,16 @@ class FSPagerViewCollectionView: UICollectionView {
super.init(coder: aDecoder)
self.commonInit()
}

fileprivate func commonInit() {
self.contentInset = .zero
self.scrollsToTop = false
self.isPagingEnabled = false
self.decelerationRate = UIScrollViewDecelerationRateFast
self.showsVerticalScrollIndicator = false
self.showsHorizontalScrollIndicator = false
#if !os(tvOS)
self.scrollsToTop = false
self.isPagingEnabled = false
#endif
}

}
9 changes: 7 additions & 2 deletions Sources/FSPagerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
}
}


/// A Boolean value indicates that whether the pager view has infinite items. Default is false.
@IBInspectable
open var isInfinite: Bool = false {
Expand Down Expand Up @@ -148,17 +147,23 @@ open class FSPagerView: UIView,UICollectionViewDataSource,UICollectionViewDelega
}
}

// MARK: - Public readonly-properties

/// Returns whether the user has touched the content to initiate scrolling.
open var isTracking: Bool {
return self.collectionView.isTracking
}

/// The percentage of x position at which the origin of the content view is offset from the origin of the pagerView view.
open var scrollOffset: CGFloat {
let scrollOffset = Double(self.collectionView.contentOffset.x.divided(by: self.collectionViewLayout.itemSpan))
return fmod(CGFloat(scrollOffset), CGFloat(Double(self.numberOfItems)))
}

// MARK: - Public readonly-properties
/// The underlying gesture recognizer for pan gestures.
open var panGestureRecognizer: UIPanGestureRecognizer {
return self.collectionView.panGestureRecognizer
}

open fileprivate(set) dynamic var currentIndex: Int = 0

Expand Down

0 comments on commit 5f16081

Please sign in to comment.