From e85b4ccb959d017e1ae3826986cc64ff5d99a9a5 Mon Sep 17 00:00:00 2001 From: Dmitriy Demchenko Date: Fri, 11 Nov 2016 17:05:00 +0200 Subject: [PATCH] [Update] LICENSE file [Add] ExampleViewController: overrided viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) [Add] Segmentio: added function interfaceOrientationDidChange [Remove] Segmentio: removed var cachedOrientation --- Example/Segmentio/Info.plist | 2 ++ .../ExampleViewController.swift | 10 +++++- LICENSE | 4 +-- Segmentio/Source/Segmentio.swift | 33 +++++-------------- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/Example/Segmentio/Info.plist b/Example/Segmentio/Info.plist index 737fc80..7e86183 100644 --- a/Example/Segmentio/Info.plist +++ b/Example/Segmentio/Info.plist @@ -33,6 +33,8 @@ UISupportedInterfaceOrientations UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight diff --git a/Example/Segmentio/ViewControllers/ExampleViewController.swift b/Example/Segmentio/ViewControllers/ExampleViewController.swift index 379be26..927c15c 100644 --- a/Example/Segmentio/ViewControllers/ExampleViewController.swift +++ b/Example/Segmentio/ViewControllers/ExampleViewController.swift @@ -51,6 +51,14 @@ class ExampleViewController: UIViewController { setupBadgeCountForIndex(1) } + override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { + super.viewWillTransition(to: size, with: coordinator) + + coordinator.animate(alongsideTransition: { [weak self] _ in + self?.segmentioView.interfaceOrientationDidChange() + }, completion: nil) + } + fileprivate func setupSegmentioView() { segmentioView.setup( content: segmentioContent(), @@ -116,7 +124,7 @@ class ExampleViewController: UIViewController { titleTextColor: ColorPalette.grayChateau ), selectedState: segmentioState( - backgroundColor: .clear, + backgroundColor: .cyan, titleFont: font, titleTextColor: ColorPalette.black ), diff --git a/LICENSE b/LICENSE index dd4e023..228d900 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright © 2015 Yalantis +Copyright © 2016 Yalantis Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE. diff --git a/Segmentio/Source/Segmentio.swift b/Segmentio/Source/Segmentio.swift index 9ab7859..64887c9 100644 --- a/Segmentio/Source/Segmentio.swift +++ b/Segmentio/Source/Segmentio.swift @@ -55,20 +55,8 @@ open class Segmentio: UIView { fileprivate var indicatorLayer: CAShapeLayer? fileprivate var selectedLayer: CAShapeLayer? - fileprivate var cachedOrientation: UIInterfaceOrientation? = UIApplication.shared.statusBarOrientation { - didSet { - if cachedOrientation != oldValue { - reloadSegmentio() - } - } - } - // MARK: - Lifecycle - deinit { - NotificationCenter.default.removeObserver(self) - } - required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) commonInit() @@ -81,12 +69,6 @@ open class Segmentio: UIView { fileprivate func commonInit() { setupSegmentedCollectionView() - NotificationCenter.default.addObserver( - self, - selector: #selector(Segmentio.handleOrientationNotification), - name: NSNotification.Name.UIDeviceOrientationDidChange, - object: nil - ) } fileprivate func setupSegmentedCollectionView() { @@ -144,12 +126,6 @@ open class Segmentio: UIView { ) } - // MARK: - Handle orientation notification - - @objc fileprivate func handleOrientationNotification() { - cachedOrientation = UIApplication.shared.statusBarOrientation - } - // MARK: - Setups: // MARK: Main setup @@ -211,6 +187,12 @@ open class Segmentio: UIView { segmentioCollectionView?.reloadData() } + open func interfaceOrientationDidChange() { + segmentioCollectionView?.collectionViewLayout.invalidateLayout() + scrollToItemAtContext() + moveShapeLayerAtContext() + } + // MARK: Collection view setup fileprivate func setupCellWithStyle(_ style: SegmentioStyle) { @@ -341,7 +323,8 @@ open class Segmentio: UIView { // MARK: - Actions: // MARK: Reload segmentio public func reloadSegmentio() { - segmentioCollectionView?.reloadData() +// segmentioCollectionView?.reloadData() + segmentioCollectionView?.collectionViewLayout.invalidateLayout() scrollToItemAtContext() moveShapeLayerAtContext() }