|
import UIKit |
|
|
|
extension UIView { |
|
|
|
public func constraintsForPinningToHomeButton(withSpacing spacing: CGFloat = 0.0) -> [NSLayoutConstraint] { |
|
|
|
guard let superview = superview else { return [] } |
|
|
|
switch (UIDevice.current().orientation, UIApplication.shared().statusBarOrientation) { |
|
case (.landscapeLeft, .landscapeRight): |
|
let centerConstraint = centerYAnchor.constraint(equalTo: superview.centerYAnchor) |
|
centerConstraint.isActive = true |
|
centerConstraint.identifier = "View centered vertically in superview" |
|
|
|
let rightConstraint = rightAnchor.constraint(equalTo: superview.rightAnchor, constant: -spacing) |
|
rightConstraint.isActive = true |
|
rightConstraint.identifier = "View anchored to right side of superview" |
|
|
|
return [centerConstraint, rightConstraint] |
|
|
|
case (.landscapeRight, .landscapeLeft): |
|
let centerConstraint = centerYAnchor.constraint(equalTo: superview.centerYAnchor) |
|
centerConstraint.isActive = true |
|
centerConstraint.identifier = "Vuew centered vertically in superview" |
|
|
|
let leftConstraint = leftAnchor.constraint(equalTo: superview.leftAnchor, constant: spacing) |
|
leftConstraint.isActive = true |
|
leftConstraint.identifier = "Take Picture button anchored to right side of view" |
|
|
|
return [centerConstraint, leftConstraint] |
|
|
|
default: |
|
let bottomConstraint = bottomAnchor.constraint(equalTo: superview.bottomAnchor, constant: -20) |
|
bottomConstraint.isActive = true |
|
bottomConstraint.identifier = "View anchored to bottom of superview" |
|
|
|
let centerConstraint = centerXAnchor.constraint(equalTo: superview.centerXAnchor) |
|
centerConstraint.isActive = true |
|
centerConstraint.identifier = "View centered horizontally in superview" |
|
|
|
return [bottomConstraint, centerConstraint] |
|
} |
|
|
|
} |
|
|
|
} |