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
68 changes: 46 additions & 22 deletions Example/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions Example/PopupViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class PopupViewController: UIViewController {
@IBOutlet weak var tabItemViewWidthSlider: UISlider!
@IBOutlet weak var tabAdditionSegmentedControl: UISegmentedControl!
@IBOutlet weak var contentScrolEnabledSegmentedControl: UISegmentedControl!
@IBOutlet weak var languageDirectionSegmentedControl: UISegmentedControl!

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -88,6 +89,12 @@ class PopupViewController: UIViewController {
} else {
contentScrolEnabledSegmentedControl.selectedSegmentIndex = 1
}

if options.isLanguageRTL {
languageDirectionSegmentedControl.selectedSegmentIndex = 1
} else {
languageDirectionSegmentedControl.selectedSegmentIndex = 0
}
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
Expand Down Expand Up @@ -196,4 +203,16 @@ class PopupViewController: UIViewController {
break
}
}

@IBAction func changeLanguageDirection(_ sender: UISegmentedControl) {

switch sender.selectedSegmentIndex {
case 0:
options.isLanguageRTL = false
case 1:
options.isLanguageRTL = true
default:
break
}
}
}
41 changes: 38 additions & 3 deletions Sources/Classes/ContentScrollView.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import UIKit

// MARK: - ContentScrollViewDataSource
public protocol ContentScrollViewDataSource {

func numberOfPages(in contentScrollView: ContentScrollView) -> Int

func contentScrollView(_ contentScrollView: ContentScrollView, viewForPageAt index: Int) -> UIView?
}

// MARK: - ContentScrollView
open class ContentScrollView: UIScrollView {

open var dataSource: ContentScrollViewDataSource?
Expand Down Expand Up @@ -48,6 +50,7 @@ open class ContentScrollView: UIScrollView {
public func reset() {
pageViews = []
currentIndex = 0
self.subviews.forEach({ $0.removeFromSuperview() })
}

public func reload() {
Expand All @@ -57,6 +60,16 @@ open class ContentScrollView: UIScrollView {
public func update(_ newIndex: Int) {
currentIndex = newIndex
}

func updateSemantic() {
if #available(iOS 9.0, *) {
if options.isLanguageRTL {
self.semanticContentAttribute = .forceRightToLeft
} else {
self.semanticContentAttribute = .forceLeftToRight
}
}
}

// MARK: - Setup

Expand Down Expand Up @@ -102,23 +115,38 @@ open class ContentScrollView: UIScrollView {
pageView.widthAnchor.constraint(equalTo: self.widthAnchor),
pageView.heightAnchor.constraint(equalTo: self.heightAnchor),
pageView.leadingAnchor.constraint(equalTo: leadingAnchor)
])
])
}

guard currentIndex < dataSource.numberOfPages(in: self) else { return }

var lastPageView :UIView?

for i in (currentIndex + 1)..<dataSource.numberOfPages(in: self) {
guard let pageView = dataSource.contentScrollView(self, viewForPageAt: i) else { return }
pageViews.append(pageView)
addSubview(pageView)

pageView.translatesAutoresizingMaskIntoConstraints = false

lastPageView = pageView

NSLayoutConstraint.activate([
pageView.topAnchor.constraint(equalTo: self.topAnchor),
pageView.widthAnchor.constraint(equalTo: self.widthAnchor),
pageView.heightAnchor.constraint(equalTo: self.heightAnchor),
pageView.leadingAnchor.constraint(equalTo: pageViews[i - 1].trailingAnchor)
])
])
}


if let lastView = lastPageView {
NSLayoutConstraint.activate([
lastView.trailingAnchor.constraint(equalTo: self.trailingAnchor)
])
}


}
}

Expand Down Expand Up @@ -153,6 +181,13 @@ extension ContentScrollView {

public func jump(to index: Int, animated: Bool) {
update(index)
self.setContentOffset(CGPoint(x: self.frame.width * CGFloat(currentIndex), y: 0), animated: animated)

if options.isLanguageRTL {
self.setContentOffset(CGPoint(x: self.frame.width * CGFloat((pageViews.count - 1) - currentIndex), y: 0), animated: animated)
} else {
self.setContentOffset(CGPoint(x: self.frame.width * CGFloat(currentIndex), y: 0), animated: animated)
}


}
}
Loading