ViewState
Adds an ability to check current view controller's view state and also to subscribe to view state changes notifications. Also, adds several helpful properties to easily configure some complex behaviors in xibs and storyboards.
Example
Clone the repo and then open Carthage Project/ViewState.xcodeproj
Installation
Carthage
Please check official guide
Cartfile:
github "APUtils/ViewState" ~> 2.0
Install command: carthage bootstrap --use-xcframeworks
CocoaPods
ViewState is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ViewState', '~> 2.0'
Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.
Once you have your Swift package set up, adding ViewState
as a dependency is as easy as adding it to the dependencies value of your Package.swift
.
ViewState.setupOnce()
somewhere in you code or it won't work. The issue is that SPM doesn't support mixed source code and the framework can't load himself without Objective-C part.
dependencies: [
.package(url: "https://github.com/APUtils/ViewState.git", .upToNextMajor(from: "2.0.0"))
]
Usage
UIViewController subclasses
- Extends UIViewController with .viewState enum property. Possible cases:
.notLoaded
,.didLoad
,.willAppear
,.didAppear
,.willDisappear
,.didDisappear
. - Every UIViewController starts to send notifications about its state change. Available notifications to observe:
.UIViewControllerWillMoveToParentViewController
,.UIViewControllerViewDidLoad
,.UIViewControllerViewWillAppear
,.UIViewControllerViewDidAppear
,.UIViewControllerViewWillDisappear
,.UIViewControllerViewDidDisappear
. You could checkuserInfo
notification's dictionary for parameters if needed. - Adds
.hideKeyboardOnTouch
@IBInspectable property to hide keyboard on touch outside.
UIResponder subclasses
- Adds
.becomeFirstResponderOnViewDidAppear
@IBInspectable property to become first responser onviewDidAppear
.
UIScrollView subclasses
- Adds
.flashScrollIndicatorsOnViewDidAppear
@IBInspectable property to flash scroll indicators onviewDidAppear
.
See example and test projects for more details.
Contributions
Any contribution is more than welcome! You can contribute through pull requests and issues on GitHub.
Author
Anton Plebanovich, [email protected]
License
ViewState is available under the MIT license. See the LICENSE file for more info.