Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
Fix page Fix offset after rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
hebertialmeida committed Jul 11, 2016
1 parent e42df5c commit af62dcf
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Source/FolioReaderCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio

private var screenBounds: CGRect!
private var pointNow = CGPointZero
private let pageIndicatorHeight = 20 as CGFloat
private let pageIndicatorHeight: CGFloat = 20
private var pageOffsetRate: CGFloat = 0

// MARK: - View life cicle

Expand Down Expand Up @@ -549,7 +550,7 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
self.pageIndicatorView.frame = pageIndicatorFrame
self.pageIndicatorView.reloadView(updateShadow: true)

// adjust scroll scrubber slider
// Adjust scroll scrubber slider
self.scrollScrubber.slider.frame = scrollScrubberFrame

// Adjust collectionView
Expand All @@ -573,6 +574,18 @@ class FolioReaderCenter: UIViewController, UICollectionViewDelegate, UICollectio
pagesForCurrentPage(currentPage)

scrollScrubber.setSliderVal()

// After rotation fix internal page offset
var pageOffset = self.currentPage.webView.scrollView.contentSize.forDirection() * pageOffsetRate

// Fix the offset for paged scroll
if readerConfig.scrollDirection == .horizontal {
var page = round(pageOffset / pageWidth)
pageOffset = page * pageWidth
}

let pageOffsetPoint = isVerticalDirection(CGPoint(x: 0, y: pageOffset), CGPoint(x: pageOffset, y: 0))
self.currentPage.webView.scrollView.setContentOffset(pageOffsetPoint, animated: true)
}

override func willAnimateRotationToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
Expand Down

0 comments on commit af62dcf

Please sign in to comment.