From 7cce5ffddab4f297b3999391e134b49c134f8d5e Mon Sep 17 00:00:00 2001 From: PanajotisMaroungas Date: Fri, 5 Aug 2016 14:09:23 +0200 Subject: [PATCH 01/10] hideBars config variable is added and FolioReaderContainer is public. ScrollDirection is extented with the 'sectionHorizontalContentVertical' option. --- Source/FolioReaderCenter.swift | 4 ++-- Source/FolioReaderConfig.swift | 7 ++++-- Source/FolioReaderContainer.swift | 21 +++++++++++------ Source/FolioReaderPage.swift | 38 +++++++++++++++++-------------- 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/Source/FolioReaderCenter.swift b/Source/FolioReaderCenter.swift index 3e26d5fa4..e83b91f48 100755 --- a/Source/FolioReaderCenter.swift +++ b/Source/FolioReaderCenter.swift @@ -31,7 +31,8 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio var animator: ZFModalTransitionAnimator! var pageIndicatorView: FolioReaderPageIndicator! var bookShareLink: String? - + var pageIndicatorHeight: CGFloat = 20 + var recentlyScrolled = false var recentlyScrolledDelay = 2.0 // 2 second delay until we clear recentlyScrolled var recentlyScrolledTimer: NSTimer! @@ -39,7 +40,6 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio private var screenBounds: CGRect! private var pointNow = CGPointZero - private let pageIndicatorHeight: CGFloat = 20 private var pageOffsetRate: CGFloat = 0 private var tempReference: FRTocReference? private var isFirstLoad = true diff --git a/Source/FolioReaderConfig.swift b/Source/FolioReaderConfig.swift index 087416dca..9c8bb26c8 100755 --- a/Source/FolioReaderConfig.swift +++ b/Source/FolioReaderConfig.swift @@ -11,6 +11,7 @@ import UIKit public enum FolioReaderScrollDirection: Int { case vertical case horizontal + case sectionHorizontalContentVertical /** The current scroll direction @@ -19,7 +20,7 @@ public enum FolioReaderScrollDirection: Int { */ func collectionViewScrollDirection() -> UICollectionViewScrollDirection { switch self { - case vertical: + case vertical, sectionHorizontalContentVertical: return .Vertical case horizontal: return .Horizontal @@ -41,7 +42,9 @@ public class FolioReaderConfig: NSObject { public lazy var mediaOverlayColor: UIColor! = self.tintColor // MARK: Custom actions - + /// hide the navigation bar and the bottom status view + public var hideAllBars = false + /// If `canChangeScrollDirection` is `true` it will be overrided by user's option. public var scrollDirection: FolioReaderScrollDirection = .vertical diff --git a/Source/FolioReaderContainer.swift b/Source/FolioReaderContainer.swift index a015e3331..771cf5473 100755 --- a/Source/FolioReaderContainer.swift +++ b/Source/FolioReaderContainer.swift @@ -13,7 +13,7 @@ var readerConfig: FolioReaderConfig! var epubPath: String? var book: FRBook! -class FolioReaderContainer: UIViewController { +public class FolioReaderContainer: UIViewController { var centerNavigationController: UINavigationController! var centerViewController: FolioReaderCenter! var audioPlayer: FolioReaderAudioPlayer! @@ -23,7 +23,7 @@ class FolioReaderContainer: UIViewController { // MARK: - Init - required init?(coder aDecoder: NSCoder) { + required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) } @@ -54,7 +54,7 @@ class FolioReaderContainer: UIViewController { // MARK: - View life cicle - override func viewDidLoad() { + override public func viewDidLoad() { super.viewDidLoad() // If user can change scroll direction use the last saved @@ -72,6 +72,13 @@ class FolioReaderContainer: UIViewController { addChildViewController(centerNavigationController) centerNavigationController.didMoveToParentViewController(self) + if (readerConfig.hideAllBars == true) { + readerConfig.shouldHideNavigationOnTap = false + readerConfig.scrollDirection = .sectionHorizontalContentVertical + self.navigationController?.navigationBar.hidden = true + self.centerViewController.pageIndicatorHeight = 0 + } + // Read async book if (epubPath != nil) { let priority = DISPATCH_QUEUE_PRIORITY_HIGH @@ -115,7 +122,7 @@ class FolioReaderContainer: UIViewController { } } - override func viewDidAppear(animated: Bool) { + override public func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) if errorOnLoad { @@ -133,15 +140,15 @@ class FolioReaderContainer: UIViewController { // MARK: - Status Bar - override func prefersStatusBarHidden() -> Bool { + override public func prefersStatusBarHidden() -> Bool { return readerConfig.shouldHideNavigationOnTap == false ? false : shouldHideStatusBar } - override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation { + override public func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation { return UIStatusBarAnimation.Slide } - override func preferredStatusBarStyle() -> UIStatusBarStyle { + override public func preferredStatusBarStyle() -> UIStatusBarStyle { return isNight(.LightContent, .Default) } } diff --git a/Source/FolioReaderPage.swift b/Source/FolioReaderPage.swift index 191c2bb35..d232addd7 100755 --- a/Source/FolioReaderPage.swift +++ b/Source/FolioReaderPage.swift @@ -78,21 +78,21 @@ class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRecogni } func webViewFrame() -> CGRect { - let paddingTop: CGFloat = 20 - let paddingBottom: CGFloat = 30 - - guard readerConfig.shouldHideNavigationOnTap else { - let statusbarHeight = UIApplication.sharedApplication().statusBarFrame.size.height - let navBarHeight = FolioReader.sharedInstance.readerCenter.navigationController?.navigationBar.frame.size.height - let navTotal = statusbarHeight + navBarHeight! - let newFrame = CGRect( - x: bounds.origin.x, - y: isVerticalDirection(bounds.origin.y + navTotal, bounds.origin.y + navTotal + paddingTop), - width: bounds.width, - height: isVerticalDirection(bounds.height - navTotal, bounds.height - navTotal - paddingTop - paddingBottom)) - return newFrame - } - + let paddingTop: CGFloat = ((readerConfig.hideAllBars == true) ? 0 : 20) + let paddingBottom: CGFloat = ((readerConfig.hideAllBars == true) ? 0 : 30) + + guard (readerConfig.shouldHideNavigationOnTap && readerConfig.hideAllBars == true) else { + let statusbarHeight = UIApplication.sharedApplication().statusBarFrame.size.height + let navBarHeight = FolioReader.sharedInstance.readerCenter.navigationController?.navigationBar.frame.size.height + let navTotal = statusbarHeight + navBarHeight! + let newFrame = CGRect( + x: bounds.origin.x, + y: isVerticalDirection(bounds.origin.y + navTotal, bounds.origin.y + navTotal + paddingTop), + width: bounds.width, + height: isVerticalDirection(bounds.height - navTotal, bounds.height - navTotal - paddingTop - paddingBottom)) + return newFrame + } + let newFrame = CGRect( x: bounds.origin.x, y: isVerticalDirection(bounds.origin.y, bounds.origin.y + paddingTop), @@ -620,11 +620,15 @@ extension UIWebView { paginationMode = .LeftToRight paginationBreakingMode = .Page scrollView.bounces = false - } else { + } else if readerConfig.scrollDirection == .vertical { scrollView.pagingEnabled = false paginationMode = .Unpaginated scrollView.bounces = true - } + } else { + // swipe paragraphs horizontal, read content vertical + scrollView.bounces = true + self.scrollView.showsVerticalScrollIndicator = true + } } } From 6cbb26f187bfa7f4d35e4342b154d1758a13f686 Mon Sep 17 00:00:00 2001 From: PanajotisMaroungas Date: Fri, 5 Aug 2016 14:11:26 +0200 Subject: [PATCH 02/10] 'hideBars' renaming --- Source/FolioReaderConfig.swift | 2 +- Source/FolioReaderContainer.swift | 2 +- Source/FolioReaderPage.swift | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/FolioReaderConfig.swift b/Source/FolioReaderConfig.swift index 9c8bb26c8..c6e351a1c 100755 --- a/Source/FolioReaderConfig.swift +++ b/Source/FolioReaderConfig.swift @@ -43,7 +43,7 @@ public class FolioReaderConfig: NSObject { // MARK: Custom actions /// hide the navigation bar and the bottom status view - public var hideAllBars = false + public var hideBars = false /// If `canChangeScrollDirection` is `true` it will be overrided by user's option. public var scrollDirection: FolioReaderScrollDirection = .vertical diff --git a/Source/FolioReaderContainer.swift b/Source/FolioReaderContainer.swift index 771cf5473..4fb7046e3 100755 --- a/Source/FolioReaderContainer.swift +++ b/Source/FolioReaderContainer.swift @@ -72,7 +72,7 @@ public class FolioReaderContainer: UIViewController { addChildViewController(centerNavigationController) centerNavigationController.didMoveToParentViewController(self) - if (readerConfig.hideAllBars == true) { + if (readerConfig.hideBars == true) { readerConfig.shouldHideNavigationOnTap = false readerConfig.scrollDirection = .sectionHorizontalContentVertical self.navigationController?.navigationBar.hidden = true diff --git a/Source/FolioReaderPage.swift b/Source/FolioReaderPage.swift index d232addd7..be040c0e9 100755 --- a/Source/FolioReaderPage.swift +++ b/Source/FolioReaderPage.swift @@ -78,10 +78,10 @@ class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRecogni } func webViewFrame() -> CGRect { - let paddingTop: CGFloat = ((readerConfig.hideAllBars == true) ? 0 : 20) - let paddingBottom: CGFloat = ((readerConfig.hideAllBars == true) ? 0 : 30) + let paddingTop: CGFloat = ((readerConfig.hideBars == true) ? 0 : 20) + let paddingBottom: CGFloat = ((readerConfig.hideBars == true) ? 0 : 30) - guard (readerConfig.shouldHideNavigationOnTap && readerConfig.hideAllBars == true) else { + guard (readerConfig.shouldHideNavigationOnTap && readerConfig.hideBars == true) else { let statusbarHeight = UIApplication.sharedApplication().statusBarFrame.size.height let navBarHeight = FolioReader.sharedInstance.readerCenter.navigationController?.navigationBar.frame.size.height let navTotal = statusbarHeight + navBarHeight! From a02e406ac8b00b2ec1c6a843a2a27a9e97688f6f Mon Sep 17 00:00:00 2001 From: PanajotisMaroungas Date: Mon, 8 Aug 2016 12:17:01 +0200 Subject: [PATCH 03/10] webview's frame == screen's size if AllhideBars == true --- Source/FolioReaderPage.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/FolioReaderPage.swift b/Source/FolioReaderPage.swift index be040c0e9..0adcb50d1 100755 --- a/Source/FolioReaderPage.swift +++ b/Source/FolioReaderPage.swift @@ -78,10 +78,15 @@ class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRecogni } func webViewFrame() -> CGRect { + + if (readerConfig.hideBars == true) { + return UIScreen.mainScreen().bounds + } + let paddingTop: CGFloat = ((readerConfig.hideBars == true) ? 0 : 20) let paddingBottom: CGFloat = ((readerConfig.hideBars == true) ? 0 : 30) - guard (readerConfig.shouldHideNavigationOnTap && readerConfig.hideBars == true) else { + guard (readerConfig.shouldHideNavigationOnTap) else { let statusbarHeight = UIApplication.sharedApplication().statusBarFrame.size.height let navBarHeight = FolioReader.sharedInstance.readerCenter.navigationController?.navigationBar.frame.size.height let navTotal = statusbarHeight + navBarHeight! From 966368f2c8ca90f1d79139dde228a6dffbe7af21 Mon Sep 17 00:00:00 2001 From: PanajotisMaroungas Date: Mon, 8 Aug 2016 13:52:31 +0200 Subject: [PATCH 04/10] minor changes, improve behaviour of the scrollview --- Source/FolioReaderCenter.swift | 2 +- Source/FolioReaderConfig.swift | 4 ++-- Source/FolioReaderContainer.swift | 7 ++++--- Source/FolioReaderPage.swift | 6 +++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Source/FolioReaderCenter.swift b/Source/FolioReaderCenter.swift index e83b91f48..f3661132c 100755 --- a/Source/FolioReaderCenter.swift +++ b/Source/FolioReaderCenter.swift @@ -87,7 +87,7 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio pageIndicatorView = FolioReaderPageIndicator(frame: CGRect(x: 0, y: view.frame.height-pageIndicatorHeight, width: view.frame.width, height: pageIndicatorHeight)) view.addSubview(pageIndicatorView) - let scrubberY: CGFloat = readerConfig.shouldHideNavigationOnTap == true ? 50 : 74 + let scrubberY: CGFloat = ((readerConfig.shouldHideNavigationOnTap == true || readerConfig.hideBars == true) ? 50 : 74) scrollScrubber = ScrollScrubber(frame: CGRect(x: pageWidth + 10, y: scrubberY, width: 40, height: pageHeight - 100)) scrollScrubber.delegate = self view.addSubview(scrollScrubber.slider) diff --git a/Source/FolioReaderConfig.swift b/Source/FolioReaderConfig.swift index c6e351a1c..2d61cb61d 100755 --- a/Source/FolioReaderConfig.swift +++ b/Source/FolioReaderConfig.swift @@ -20,9 +20,9 @@ public enum FolioReaderScrollDirection: Int { */ func collectionViewScrollDirection() -> UICollectionViewScrollDirection { switch self { - case vertical, sectionHorizontalContentVertical: + case vertical: return .Vertical - case horizontal: + case horizontal, sectionHorizontalContentVertical: return .Horizontal } } diff --git a/Source/FolioReaderContainer.swift b/Source/FolioReaderContainer.swift index 4fb7046e3..c29909d11 100755 --- a/Source/FolioReaderContainer.swift +++ b/Source/FolioReaderContainer.swift @@ -58,11 +58,13 @@ public class FolioReaderContainer: UIViewController { super.viewDidLoad() // If user can change scroll direction use the last saved - if readerConfig.canChangeScrollDirection { + if (readerConfig.canChangeScrollDirection && readerConfig.scrollDirection != .sectionHorizontalContentVertical) { let direction = FolioReaderScrollDirection(rawValue: FolioReader.currentScrollDirection) ?? .vertical readerConfig.scrollDirection = direction } - + + readerConfig.shouldHideNavigationOnTap = ((readerConfig.hideBars == true) ? true : readerConfig.shouldHideNavigationOnTap) + centerViewController = FolioReaderCenter() FolioReader.sharedInstance.readerCenter = centerViewController @@ -74,7 +76,6 @@ public class FolioReaderContainer: UIViewController { if (readerConfig.hideBars == true) { readerConfig.shouldHideNavigationOnTap = false - readerConfig.scrollDirection = .sectionHorizontalContentVertical self.navigationController?.navigationBar.hidden = true self.centerViewController.pageIndicatorHeight = 0 } diff --git a/Source/FolioReaderPage.swift b/Source/FolioReaderPage.swift index 0adcb50d1..4f71082e5 100755 --- a/Source/FolioReaderPage.swift +++ b/Source/FolioReaderPage.swift @@ -83,10 +83,10 @@ class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRecogni return UIScreen.mainScreen().bounds } - let paddingTop: CGFloat = ((readerConfig.hideBars == true) ? 0 : 20) - let paddingBottom: CGFloat = ((readerConfig.hideBars == true) ? 0 : 30) + let paddingTop: CGFloat = 20 + let paddingBottom: CGFloat = 30 - guard (readerConfig.shouldHideNavigationOnTap) else { + guard readerConfig.shouldHideNavigationOnTap else { let statusbarHeight = UIApplication.sharedApplication().statusBarFrame.size.height let navBarHeight = FolioReader.sharedInstance.readerCenter.navigationController?.navigationBar.frame.size.height let navTotal = statusbarHeight + navBarHeight! From 8ff6a52afc9f567df8b55b18dd8be7e759dd401a Mon Sep 17 00:00:00 2001 From: PanajotisMaroungas Date: Tue, 9 Aug 2016 09:18:44 +0200 Subject: [PATCH 05/10] update readme.md --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6ab6a7414..663406290 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Then, follow the steps as described in Carthage's [README](https://github.com/Ca ## Basic Usage -To get started, this is a simple usage sample. +To get started, this is a simple usage sample of using the integrated view controller. ```swift import FolioReaderKit @@ -68,6 +68,18 @@ func open(sender: AnyObject) { } ``` +You can also use your own FolioReader view controller like this. + +```swift + let config = FolioReaderConfig() + + let bookPath = NSBundle.mainBundle().pathForResource("bible", ofType: "epub") + let epubVC = FolioReaderContainer(config: config, epubPath: bookPath, removeEpub: true) + FolioReader.sharedInstance.readerContainer = epubVC + + self.presentViewController(epubVC, animated: true, completion: nil) +``` + In your AppDelegate call `applicationWillResignActive` and `applicationWillTerminate`. This will save the reader state even if you kill the app. ```swift @@ -82,6 +94,8 @@ func applicationWillTerminate(application: UIApplication) { } ``` + + ## Features - [x] Custom Fonts @@ -96,7 +110,7 @@ func applicationWillTerminate(application: UIApplication) { - [x] Media Overlays (Sync text rendering with audio playback) - [x] TTS - Text to Speech Support - [x] Parse epub cover image -- [x] Vertical and Horizontal scrolling +- [x] Vertical or/and Horizontal scrolling - [x] RTL Support - [ ] PDF support - [ ] Book Search From ec5a2ec7efbf94deb1fb342361d2c18e9a3cdc1f Mon Sep 17 00:00:00 2001 From: PanajotisMaroungas Date: Tue, 9 Aug 2016 09:29:25 +0200 Subject: [PATCH 06/10] update Readme md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 663406290..593ae80ec 100644 --- a/README.md +++ b/README.md @@ -73,10 +73,11 @@ You can also use your own FolioReader view controller like this. ```swift let config = FolioReaderConfig() - let bookPath = NSBundle.mainBundle().pathForResource("bible", ofType: "epub") + let bookPath = NSBundle.mainBundle().pathForResource("book", ofType: "epub") let epubVC = FolioReaderContainer(config: config, epubPath: bookPath, removeEpub: true) FolioReader.sharedInstance.readerContainer = epubVC + // present the epubVC view controller like every other UIViewController instance self.presentViewController(epubVC, animated: true, completion: nil) ``` From b05733b68f5c9879f3287b9b1e3385095b26ecb8 Mon Sep 17 00:00:00 2001 From: PanajotisMaroungas Date: Tue, 9 Aug 2016 09:30:42 +0200 Subject: [PATCH 07/10] remove empty lines --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 593ae80ec..0dc6b63d0 100644 --- a/README.md +++ b/README.md @@ -95,8 +95,6 @@ func applicationWillTerminate(application: UIApplication) { } ``` - - ## Features - [x] Custom Fonts From 2d5b67ae72ac6658511044d6af48bb6af5645ab7 Mon Sep 17 00:00:00 2001 From: PanajotisMaroungas Date: Thu, 11 Aug 2016 13:45:54 +0200 Subject: [PATCH 08/10] Update open/close book function, swipe between sections without scrolling to the top. Minor refactoring --- Source/FolioReaderCenter.swift | 42 +++++++++++++++++++++++++------ Source/FolioReaderContainer.swift | 7 +++++- Source/FolioReaderKit.swift | 2 +- Source/FolioReaderPage.swift | 15 ++++++----- 4 files changed, 50 insertions(+), 16 deletions(-) diff --git a/Source/FolioReaderCenter.swift b/Source/FolioReaderCenter.swift index f3661132c..43332e1f4 100755 --- a/Source/FolioReaderCenter.swift +++ b/Source/FolioReaderCenter.swift @@ -43,6 +43,7 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio private var pageOffsetRate: CGFloat = 0 private var tempReference: FRTocReference? private var isFirstLoad = true + private var currentWebViewScrollPositions = [Int: CGPoint]() // MARK: - View life cicle @@ -878,14 +879,31 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio pageIndicatorView.currentPage = webViewPage } } - } - + + if (readerConfig.scrollDirection == .sectionHorizontalContentVertical), + let cell = ((scrollView.superview as? UIWebView)?.delegate as? FolioReaderPage) { + + let currentIndexPathRow = cell.pageNumber - 1 + + // if the cell reload don't save the top position offset + if let oldOffSet = self.currentWebViewScrollPositions[currentIndexPathRow] + where (abs(oldOffSet.y - scrollView.contentOffset.y) > 100) {} else { + self.currentWebViewScrollPositions[currentIndexPathRow] = scrollView.contentOffset + } + } + } scrollDirection = scrollView.contentOffset.forDirection() < pointNow.forDirection() ? .negative() : .positive() } func scrollViewDidEndDecelerating(scrollView: UIScrollView) { isScrolling = false - + + if (readerConfig.scrollDirection == .sectionHorizontalContentVertical), + let cell = ((scrollView.superview as? UIWebView)?.delegate as? FolioReaderPage) { + let currentIndexPathRow = cell.pageNumber - 1 + self.currentWebViewScrollPositions[currentIndexPathRow] = scrollView.contentOffset + } + if scrollView is UICollectionView { if totalPages > 0 { updateCurrentPage() } } @@ -991,11 +1009,14 @@ extension FolioReaderCenter: FolioReaderPageDelegate { if let position = FolioReader.defaults.valueForKey(kBookId) as? NSDictionary { let pageNumber = position["pageNumber"]! as! Int var pageOffset: CGFloat = 0 - - if let offset = isVerticalDirection(position["pageOffsetY"], position["pageOffsetX"]) as? CGFloat { - pageOffset = offset - } - + + if readerConfig.scrollDirection == .sectionHorizontalContentVertical, + let offSetY = position["pageOffsetY"] as? CGFloat { + pageOffset = offSetY + } else if let offset = isVerticalDirection(position["pageOffsetY"], position["pageOffsetX"]) as? CGFloat { + pageOffset = offset + } + if isFirstLoad { updateCurrentPage(page) isFirstLoad = false @@ -1020,6 +1041,11 @@ extension FolioReaderCenter: FolioReaderPageDelegate { currentPage.handleAnchor(fragmentID, avoidBeginningAnchors: true, animated: true) tempFragment = nil } + + if (readerConfig.scrollDirection == .sectionHorizontalContentVertical), + let offsetPoint = self.currentWebViewScrollPositions[page.pageNumber - 1] { + page.webView.scrollView.setContentOffset(offsetPoint, animated: false) + } } } diff --git a/Source/FolioReaderContainer.swift b/Source/FolioReaderContainer.swift index c29909d11..ae1cb4839 100755 --- a/Source/FolioReaderContainer.swift +++ b/Source/FolioReaderContainer.swift @@ -50,6 +50,11 @@ public class FolioReaderContainer: UIViewController { kCurrentMediaOverlayStyle: MediaOverlayStyle.Default.rawValue, kCurrentScrollDirection: FolioReaderScrollDirection.vertical.rawValue ]) + FolioReader.sharedInstance.readerContainer = self + + if (readerConfig.scrollDirection == .sectionHorizontalContentVertical) { + readerConfig.canChangeScrollDirection = false + } } // MARK: - View life cicle @@ -58,7 +63,7 @@ public class FolioReaderContainer: UIViewController { super.viewDidLoad() // If user can change scroll direction use the last saved - if (readerConfig.canChangeScrollDirection && readerConfig.scrollDirection != .sectionHorizontalContentVertical) { + if (readerConfig.canChangeScrollDirection) { let direction = FolioReaderScrollDirection(rawValue: FolioReader.currentScrollDirection) ?? .vertical readerConfig.scrollDirection = direction } diff --git a/Source/FolioReaderKit.swift b/Source/FolioReaderKit.swift index 5db5cd0ac..7888f7ee3 100755 --- a/Source/FolioReaderKit.swift +++ b/Source/FolioReaderKit.swift @@ -54,7 +54,7 @@ enum MediaOverlayStyle: Int { * Main Library class with some useful constants and methods */ public class FolioReader : NSObject { - static let sharedInstance = FolioReader() + public static let sharedInstance = FolioReader() static let defaults = NSUserDefaults.standardUserDefaults() weak var readerCenter: FolioReaderCenter! weak var readerContainer: FolioReaderContainer! diff --git a/Source/FolioReaderPage.swift b/Source/FolioReaderPage.swift index 4f71082e5..4a9382cbe 100755 --- a/Source/FolioReaderPage.swift +++ b/Source/FolioReaderPage.swift @@ -79,9 +79,7 @@ class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRecogni func webViewFrame() -> CGRect { - if (readerConfig.hideBars == true) { - return UIScreen.mainScreen().bounds - } + guard readerConfig.hideBars == false else { return UIScreen.mainScreen().bounds } let paddingTop: CGFloat = 20 let paddingBottom: CGFloat = 30 @@ -150,7 +148,7 @@ class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRecogni let direction: ScrollDirection = FolioReader.needsRTLChange ? .positive() : .negative() - if scrollDirection == direction && isScrolling { + if scrollDirection == direction && isScrolling && readerConfig.scrollDirection != .sectionHorizontalContentVertical { scrollPageToBottom() } @@ -299,8 +297,13 @@ class FolioReaderPage: UICollectionViewCell, UIWebViewDelegate, UIGestureRecogni - parameter animated: Enable or not scrolling animation */ func scrollPageToOffset(offset: CGFloat, animated: Bool) { - let pageOffsetPoint = isVerticalDirection(CGPoint(x: 0, y: offset), CGPoint(x: offset, y: 0)) - webView.scrollView.setContentOffset(pageOffsetPoint, animated: animated) + if readerConfig.scrollDirection == .sectionHorizontalContentVertical { + let pageOffsetPoint = CGPoint(x: 0, y: offset) + webView.scrollView.setContentOffset(pageOffsetPoint, animated: animated) + } else { + let pageOffsetPoint = isVerticalDirection(CGPoint(x: 0, y: offset), CGPoint(x: offset, y: 0)) + webView.scrollView.setContentOffset(pageOffsetPoint, animated: animated) + } } /** From d9e00717f4a1c31aa58f196441473a9d4f12bc68 Mon Sep 17 00:00:00 2001 From: PanajotisMaroungas Date: Thu, 11 Aug 2016 13:48:18 +0200 Subject: [PATCH 09/10] update read file --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 0dc6b63d0..90375f5c8 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,6 @@ You can also use your own FolioReader view controller like this. let bookPath = NSBundle.mainBundle().pathForResource("book", ofType: "epub") let epubVC = FolioReaderContainer(config: config, epubPath: bookPath, removeEpub: true) - FolioReader.sharedInstance.readerContainer = epubVC // present the epubVC view controller like every other UIViewController instance self.presentViewController(epubVC, animated: true, completion: nil) From 0c66d04a6a1e32872c4e7093acf50efcaebb02c5 Mon Sep 17 00:00:00 2001 From: PanajotisMaroungas Date: Thu, 11 Aug 2016 15:48:29 +0200 Subject: [PATCH 10/10] Fix timer and page indicator for swipe and scroll mode --- Source/FolioReaderCenter.swift | 37 ++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/Source/FolioReaderCenter.swift b/Source/FolioReaderCenter.swift index 43332e1f4..7bc2a0a94 100755 --- a/Source/FolioReaderCenter.swift +++ b/Source/FolioReaderCenter.swift @@ -515,9 +515,16 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio func pagesForCurrentPage(page: FolioReaderPage?) { guard let page = page else { return } - let pageSize = isVerticalDirection(pageHeight, pageWidth) - pageIndicatorView.totalPages = Int(ceil(page.webView.scrollView.contentSize.forDirection()/pageSize)) - let webViewPage = pageForOffset(page.webView.scrollView.contentOffset.x, pageHeight: pageSize) + + var pageSize = isVerticalDirection(pageHeight, pageWidth) + pageIndicatorView.totalPages = Int(ceil(page.webView.scrollView.contentSize.forDirection()/pageSize)) + var webViewPage = pageForOffset(page.webView.scrollView.contentOffset.x, pageHeight: pageSize) + + if readerConfig.scrollDirection == .sectionHorizontalContentVertical { + pageSize = pageHeight + pageIndicatorView.totalPages = Int(ceil(page.webView.scrollView.contentSize.height/pageSize)) + webViewPage = pageForOffset(page.webView.scrollView.contentOffset.y, pageHeight: pageSize) + } pageIndicatorView.currentPage = webViewPage } @@ -874,23 +881,27 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio if let page = currentPage where page.webView.scrollView.contentOffset.forDirection()+pageSize <= page.webView.scrollView.contentSize.forDirection() { - let webViewPage = pageForOffset(page.webView.scrollView.contentOffset.forDirection(), pageHeight: pageSize) - if pageIndicatorView.currentPage != webViewPage { - pageIndicatorView.currentPage = webViewPage - } - } - if (readerConfig.scrollDirection == .sectionHorizontalContentVertical), - let cell = ((scrollView.superview as? UIWebView)?.delegate as? FolioReaderPage) { + var webViewPage = pageForOffset(page.webView.scrollView.contentOffset.forDirection(), pageHeight: pageSize) + + if (readerConfig.scrollDirection == .sectionHorizontalContentVertical), + let cell = ((scrollView.superview as? UIWebView)?.delegate as? FolioReaderPage) { let currentIndexPathRow = cell.pageNumber - 1 // if the cell reload don't save the top position offset if let oldOffSet = self.currentWebViewScrollPositions[currentIndexPathRow] - where (abs(oldOffSet.y - scrollView.contentOffset.y) > 100) {} else { - self.currentWebViewScrollPositions[currentIndexPathRow] = scrollView.contentOffset + where (abs(oldOffSet.y - scrollView.contentOffset.y) > 100) {} else { + self.currentWebViewScrollPositions[currentIndexPathRow] = scrollView.contentOffset } - } + + webViewPage = pageForOffset(page.webView.scrollView.contentOffset.y, pageHeight: pageHeight) + } + + if pageIndicatorView.currentPage != webViewPage { + pageIndicatorView.currentPage = webViewPage + } + } } scrollDirection = scrollView.contentOffset.forDirection() < pointNow.forDirection() ? .negative() : .positive() }