Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
27 changes: 12 additions & 15 deletions SwiftPages/SwiftPages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class SwiftPages: UIView {
self.containerView.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(self.containerView)

//Add the constraints to the containerView.
// Add the constraints to the containerView.
if #available(iOS 9.0, *) {
let horizontalConstraint = self.containerView.centerXAnchor.constraintEqualToAnchor(self.centerXAnchor)
let verticalConstraint = self.containerView.centerYAnchor.constraintEqualToAnchor(self.centerYAnchor)
Expand All @@ -95,7 +95,6 @@ public class SwiftPages: UIView {
NSLayoutConstraint.activateConstraints([horizontalConstraint, verticalConstraint, widthConstraint, heightConstraint])
}


// Set the scrollview
if self.aeroEffectInTopBar {
self.scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: self.containerView.frame.size.width, height: self.containerView.frame.size.height))
Expand Down Expand Up @@ -291,7 +290,7 @@ public class SwiftPages: UIView {
scrollView.contentSize = CGSize(width: CGFloat(pageCount) * scrollView.bounds.size.width, height: scrollView.bounds.size.height)
topBar.frame = CGRect(x: 0, y: 0, width: containerView.frame.size.width, height: topBarHeight)
blurView?.frame = topBar.bounds
animatedBar.frame.size = CGSize(width: (containerView.frame.size.width / (CGFloat)(viewControllerIDs.count)) * 0.8, height: animatedBarHeight)
animatedBar.frame.size = CGSize(width: (containerView.frame.size.width / CGFloat(viewControllerIDs.count)) * 0.8, height: animatedBarHeight)
if barShadow {
shadowView.frame.size = CGSize(width: containerView.frame.size.width, height: 4)
shadowViewGradient.frame = shadowView.bounds
Expand Down Expand Up @@ -326,18 +325,6 @@ public class SwiftPages: UIView {
scrollView.contentOffset = CGPoint(x: CGFloat(currentPage) * scrollView.frame.size.width, y: 0)
}

// MARK: - ScrollView delegate -

public func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
let previousPage : NSInteger = currentPage
let pageWidth : CGFloat = scrollView.frame.size.width
let fractionalPage = scrollView.contentOffset.x / pageWidth
let page : NSInteger = Int(round(fractionalPage))
if (previousPage != page) {
currentPage = page;
}
}

// MARK: - deinit -

deinit {
Expand All @@ -359,4 +346,14 @@ extension SwiftPages: UIScrollViewDelegate {
let offsetAddition = (containerView.frame.size.width / CGFloat(viewControllerIDs.count)) * 0.1
animatedBar.frame = CGRect(x: (offsetAddition + (scrollView.contentOffset.x / CGFloat(viewControllerIDs.count))), y: animatedBar.frame.origin.y, width: animatedBar.frame.size.width, height: animatedBar.frame.size.height)
}

public func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
let previousPage = currentPage
let pageWidth = scrollView.frame.size.width
let fractionalPage = scrollView.contentOffset.x / pageWidth
let page = Int(round(fractionalPage))
if previousPage != page {
currentPage = page;
}
}
}