CariocaIndicatorView
public class CariocaIndicatorView: UIView
The menu’s indicator
-
The edge of the indicator.
Declaration
Swift
var edge: UIRectEdge
-
The original edge. Used when boomerang is not .none
Declaration
Swift
private let originalEdge: UIRectEdge
-
The indicator’s top constraint
Declaration
Swift
var topConstraint = NSLayoutConstraint()
-
The indicator’s horizontal constraint.
Declaration
Swift
private var horizontalConstraint = NSLayoutConstraint()
-
The icon’s view
Declaration
Swift
var iconView: CariocaIconView
-
The custom indicator configuration
Declaration
Swift
private let config: CariocaIndicator
-
The constraints applied to the iconview. Can be updated later with custom configuration
Declaration
Swift
private var iconConstraints: [NSLayoutConstraint] = []
-
The indicator’s possible animation states
See moreDeclaration
Swift
private enum AnimationState
-
Status of the indicator animations. Avoid double animations issues
Declaration
Swift
private var state: AnimationState = .onHold
-
Initialise an IndicatorView
Declaration
Swift
init(edge: UIRectEdge, indicator: CariocaIndicator)
Parameters
edge
The inital edge. Will be updated every time the user changes of edge.
indicator
The indicator custom configuration
-
Calculates the indicator’s position for animation
Declaration
Swift
class func positionConstants(hostWidth: CGFloat, indicatorWidth: CGFloat, edge: UIRectEdge, borderMargin: CGFloat, bouncingValues: BouncingValues, startInset: CGFloat, endInset: CGFloat) -> IndicatorPositionConstants
Parameters
hostWidth
The hostView’s width
indicatorWidth
The indicator’s size
edge
The original edge
borderMargin
The border magins
bouncingValues
The values to make the bouncing effect in animations
startInset
The view’s starting inset, if applies (iPhone X safe area)
endInset
The view’s starting inset, if applies (iPhone X safe area)
Return Value
IndicatorPositionConstants All the possible calculated positions
-
Adds the indicator in the hostView
Declaration
Swift
func addIn(_ hostView: UIView, tableView: UITableView, position: CGFloat)
Parameters
hostView
the menu’s hostView
tableView
the menu’s tableView
position
the indicator initial position in %
-
Calculates the Y constraint based on percentage. A margin of 50% of the indicator view is applied for security.
Declaration
Swift
private func verticalConstant(for percentage: CGFloat, hostHeight: CGFloat, height: CGFloat) -> CGFloat
Parameters
percentage
The desired position percentage
hostHeight
The host’s height
height
The indicator’s height
Return Value
CGFloat: The constant calculated Y value
-
Create the horizontal constraint
Declaration
Swift
private func makeHorizontalConstraint(_ hostView: UIView, _ attribute: NSLayoutAttribute) -> NSLayoutConstraint
Parameters
hostView
The menu’s hostView
attribute
The layoutAttribute for the constraint
priority
The constraint’s priority
Return Value
NSLayoutConstraint the horizontal constraint
-
Draws the shape, depending on the edge.
Declaration
Swift
override public func draw(_ frame: CGRect)
Parameters
frame
The IndicatorView’s frame
-
Applies the margins to the iconView
Declaration
Swift
private func applyMarginConstraints(margins: (top: CGFloat, right: CGFloat, bottom: CGFloat, left: CGFloat))
Parameters
margins
Tuple of margins in CSS Style (Top, Right, Bottom, left)
-
Calls the positionConstants() with all internal parameters
Declaration
Swift
private func positionValues(_ hostView: UIView) -> IndicatorPositionConstants
Return Value
IndicatorPositionConstants All the possible calculated positions
-
When the hostView has rotated, re-apply the constraints. This should have an effect only on iPhone X, because of the view edges.
Declaration
Swift
func repositionXAfterRotation(_ hostView: UIView)
Parameters
hostView
The menu’s hostView
-
Calculates inset values, depending on orientation. The goal is to only have the inset on the indicator when the edge of the indicator is on the side of the notch.
Declaration
Swift
func insetsValues(_ insets: UIEdgeInsets, orientation: UIDeviceOrientation, edge: UIRectEdge) -> (start: CGFloat, end: CGFloat)
Parameters
insets
The original insets
orientation
The screen orientation
edge
The screen edge
Return Value
Start end End insets for the indicator.
-
Show the indicator on a specific edge, by animating the horizontal position
Declaration
Swift
func show(edge: UIRectEdge, hostView: UIView, isTraversingView: Bool)
Parameters
edge
The screen edge
hostView
The menu’s hostView, to calculate the positions
isTraversingView
Should the indicator traverse the hostView, and stick to the opposite edge ?
-
Retore the indicator on it’s original edge position
Declaration
Swift
func restore(hostView: UIView, boomerang: BoomerangType, initialPosition: CGFloat, firstStepDuration: Double, firstStepDone: @escaping () -> Void)
Parameters
hostView
The menu’s hostView, to calculate the positions
boomerang
The boomerang type to restore the indicator
initialPosition
The indicator initial position
firstStepDuration
Should equal the time to hide the menu. First animation is 70%, second 30%. In boomerang mode, first animation is 125% of that value.
firstStepDone
Called when the first animation is complete, with or without boomerang.
-
Animate a constraint
Declaration
Swift
internal func animation(_ view: UIView, constraint: NSLayoutConstraint, constant: CGFloat, timing: Double, options: UIViewAnimationOptions, finished: @escaping () -> Void)
Parameters
view
The view to layoutIfNeeded
constraint
The constraint to animate
constant
The new constant value
timing
The animation duration
options
The animation options
finished
Completion closure, when animation finished
-
Utility to inverse 2 constraint priorities
Declaration
Swift
internal func constraintPriorities(main: NSLayoutConstraint, second: NSLayoutConstraint)
Parameters
main
The highest priority will be applied to that constraint.
second
The lowest priority will be applied to that constraint.
-
Move the indicator to a specific index, by updating the top constraint value
Declaration
Swift
func moveTo(index: Int, heightForRow: CGFloat)
Parameters
index
The selection index of the menu, where the indicator will appear
heightForRow
The height of each menu item