[Update] LICENSE file

[Add] ExampleViewController: overrided viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)
[Add] Segmentio: added function interfaceOrientationDidChange
[Remove] Segmentio: removed var cachedOrientation
This commit is contained in:
Dmitriy Demchenko 2016-11-11 17:05:00 +02:00
parent f93e6be578
commit e85b4ccb95
4 changed files with 21 additions and 28 deletions

View File

@ -33,6 +33,8 @@
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

View File

@ -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
),

View File

@ -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.
THE SOFTWARE.

View File

@ -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()
}