| | |
| | | } |
| | | |
| | | /// SwifterSwift: Add gradient directions |
| | | struct GradientDirection { |
| | | struct GradientDirection: Sendable { |
| | | public static let topToBottom = GradientDirection(startPoint: CGPoint(x: 0.5, y: 0.0), |
| | | endPoint: CGPoint(x: 0.5, y: 1.0)) |
| | | public static let bottomToTop = GradientDirection(startPoint: CGPoint(x: 0.5, y: 1.0), |
| | |
| | | |
| | | /// SwifterSwift: Remove all gesture recognizers from view. |
| | | func removeGestureRecognizers() { |
| | | gestureRecognizers?.forEach(removeGestureRecognizer) |
| | | try? gestureRecognizers?.forEach(removeGestureRecognizer) |
| | | } |
| | | |
| | | /// SwifterSwift: Attaches gesture recognizers to the view. Attaching gesture recognizers to a view defines the |
| | |
| | | animationType: ShakeAnimationType = .easeOut, |
| | | completion: (() -> Void)? = nil) { |
| | | CATransaction.begin() |
| | | let animation: CAKeyframeAnimation |
| | | switch direction { |
| | | let animation = switch direction { |
| | | case .horizontal: |
| | | animation = CAKeyframeAnimation(keyPath: "transform.translation.x") |
| | | CAKeyframeAnimation(keyPath: "transform.translation.x") |
| | | case .vertical: |
| | | animation = CAKeyframeAnimation(keyPath: "transform.translation.y") |
| | | CAKeyframeAnimation(keyPath: "transform.translation.y") |
| | | } |
| | | switch animationType { |
| | | case .linear: |
| | |
| | | func fillToSuperview() { |
| | | // https://videos.letsbuildthatapp.com/ |
| | | translatesAutoresizingMaskIntoConstraints = false |
| | | if let superview = superview { |
| | | if let superview { |
| | | let left = leftAnchor.constraint(equalTo: superview.leftAnchor) |
| | | let right = rightAnchor.constraint(equalTo: superview.rightAnchor) |
| | | let top = topAnchor.constraint(equalTo: superview.topAnchor) |
| | |
| | | |
| | | var anchors = [NSLayoutConstraint]() |
| | | |
| | | if let top = top { |
| | | if let top { |
| | | anchors.append(topAnchor.constraint(equalTo: top, constant: topConstant)) |
| | | } |
| | | |
| | | if let left = left { |
| | | if let left { |
| | | anchors.append(leftAnchor.constraint(equalTo: left, constant: leftConstant)) |
| | | } |
| | | |
| | | if let bottom = bottom { |
| | | if let bottom { |
| | | anchors.append(bottomAnchor.constraint(equalTo: bottom, constant: -bottomConstant)) |
| | | } |
| | | |
| | | if let right = right { |
| | | if let right { |
| | | anchors.append(rightAnchor.constraint(equalTo: right, constant: -rightConstant)) |
| | | } |
| | | |