FluidAnchor is a framework that makes it easy to use Auto Layout Anchor. 🤗
- iOS 9.0+
pod 'FluidAnchor'
import FluidAnchor
class ViewController: UIViewController {
var tableView = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(tableView)
tableView.flu
.topAnchor(equalTo: view.safeAreaLayoutGuide.topAnchor)
.leftAnchor(equalTo: view.safeAreaLayoutGuide.leftAnchor)
.rightAnchor(equalTo: view.safeAreaLayoutGuide.rightAnchor)
.bottomAnchor(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
}
}
import FluidAnchor
class ProfileViewController: UIViewController {
var profileImageView = UIImageView()
override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(profileImageView)
profileImageView.flu
.topAnchor(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 5)
.leftAnchor(equalTo: view.leftAnchor, constant: 10)
.heightAnchor(equalToConstant: 50)
.widthAnchor(equalToConstant: 50)
}
}
import FluidAnchor
class ChatVC: UIViewController {
var inputBar = InputBar()
var inputBarBottomConstraint: NSLayoutConstraint?
override func viewDidLoad() {
...
// You can specify the constraint to use later when animating.
inputBar.flu
.bottomAnchor(
equalTo: view.safeAreaLayoutGuide.bottomAnchor,
constraint: &inputBarBottomConstraint
)
...
}
...
func keyboardWillShow(_ notification: Notification) {
...
inputBarBottomConstraint?.constant = (someting value)
UIView.animate(withDuration: keyboardDuration) {
view.layoutIfNeeded()
}
...
}
...
}
🇰🇷Myung gi son, audrl1010@naver.com
FluidAnchor is available under the MIT license. See the LICENSE file for more info.