[docs] UIKit.md: Navigation & Controllers section
This commit is contained in:
@@ -436,7 +436,173 @@ making part of a label tappable.
|
|||||||
|
|
||||||
## Navigation & Controllers
|
## Navigation & Controllers
|
||||||
|
|
||||||
<!-- batch 11 -->
|
<details>
|
||||||
|
<summary><b>UINavigationController</b> — completion-handler push/pop, transparent bar</summary>
|
||||||
|
|
||||||
|
### `func pushViewController(_:animated: Bool = true, completion: (() -> Void)? = nil)`
|
||||||
|
### `func popViewController(animated: Bool = true, _ completion: (() -> Void)? = nil)`
|
||||||
|
### `func popToViewController(_:animated: Bool = true, _ completion: (() -> Void)? = nil)`
|
||||||
|
The standard transitions with a completion block (wrapped in a `CATransaction`).
|
||||||
|
|
||||||
|
```swift
|
||||||
|
navigationController?.pushViewController(detail) {
|
||||||
|
print("detail is on screen")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### `func pushViewController(_:hidesBottomBar: Bool = false, animated: Bool = true)` — *not tvOS*
|
||||||
|
Push while setting `hidesBottomBarWhenPushed`.
|
||||||
|
|
||||||
|
### `func makeTransparent(withTint tint: UIColor = .white)`
|
||||||
|
Clear background + shadow, translucent, tinted bar/title.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
navigationController?.makeTransparent(withTint: .label)
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>UIViewController</b> — state, instantiation, dismissal, toasts, keyboard, observers</summary>
|
||||||
|
|
||||||
|
### `var isVisible: Bool` / `var isLoaded: Bool`
|
||||||
|
View is loaded **and** in a window. (`isLoaded` is an alias.)
|
||||||
|
|
||||||
|
### `var isModal: Bool`
|
||||||
|
Whether the controller is presented modally (vs. pushed).
|
||||||
|
|
||||||
|
### `static var className: String` / `static var identifier: String` / `static var segueID: String`
|
||||||
|
`"MyVC"`, `"idMyVC"`, `"idSegueMyVC"`.
|
||||||
|
|
||||||
|
### `static func instantiate<T>(storyBoard: String, identifier: String? = nil, bundle: Bundle? = …) -> T`
|
||||||
|
Load a controller from a storyboard by (default) `T.identifier`.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
let vc: ProfileVC = ProfileVC.instantiate(storyBoard: "Main")
|
||||||
|
```
|
||||||
|
|
||||||
|
### `static func instatiate<T>(nibName: String, bundle: Bundle? = nil) -> T` *(sic — "instatiate")*
|
||||||
|
Load from a nib and force an initial layout pass.
|
||||||
|
|
||||||
|
### `func present(viewControllerToPresent:completion: @escaping () -> Void)`
|
||||||
|
`present(_:animated:)` with a completion block.
|
||||||
|
|
||||||
|
### `func closeController(jumpToController: UIViewController? = nil, completion: @escaping () -> Void)`
|
||||||
|
Dismiss if modal, else pop (to `jumpToController` if given), then call `completion`.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
closeController { self.refreshList() }
|
||||||
|
```
|
||||||
|
|
||||||
|
### `func show(toastWith message:, font: = system 12, toastPosition: ToastPosition, backgroundColor: = .black, textColor: = .white, duration: = 3)`
|
||||||
|
Show a temporary rounded toast label. `ToastPosition` is `.top` / `.down`
|
||||||
|
(notch-aware at the top).
|
||||||
|
|
||||||
|
```swift
|
||||||
|
show(toastWith: "Saved", toastPosition: .down)
|
||||||
|
```
|
||||||
|
|
||||||
|
### `func addNotificationObserver(name:selector:)` / `func removeNotificationObserver(name:)` / `func removeNotificationsObserver()`
|
||||||
|
`NotificationCenter` registration shortcuts (last one removes all).
|
||||||
|
|
||||||
|
### `@objc func dismissSystemKeyboard(_ sender: UITapGestureRecognizer)`
|
||||||
|
Ready-made selector for a tap-to-dismiss-keyboard gesture.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
view.addGestureRecognizer(UITapGestureRecognizer(target: self,
|
||||||
|
action: #selector(dismissSystemKeyboard(_:))))
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>UITabBarController</b> — badges, animated tab switching</summary>
|
||||||
|
|
||||||
|
### `func setBadges(badgeValues: [Int], font: UIFont = Helvetica-Light 11)`
|
||||||
|
Set numeric badges for every tab at once (`0` = no badge). Custom-drawn
|
||||||
|
(`CustomTabBadge` label), so they position above each tab item.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
tabBarController?.setBadges(badgeValues: [0, 3, 0, 12])
|
||||||
|
```
|
||||||
|
|
||||||
|
### `func addBadge(index:value:color:font:)`
|
||||||
|
Add a single custom badge.
|
||||||
|
|
||||||
|
### `func setSelectedView(atIndex:withAnimation: Bool = false, completion:)`
|
||||||
|
Select a tab (pops that tab's nav stack to root first).
|
||||||
|
|
||||||
|
### `func setSelectedView(withNoPop atIndex:withAnimation: Bool = false, completion:)`
|
||||||
|
Same, without popping to root.
|
||||||
|
|
||||||
|
### `func animateToTab(toIndex: Int)`
|
||||||
|
Slide-transition between tabs.
|
||||||
|
|
||||||
|
### `func changeViewControllerToItem(withViewController:Item:)`
|
||||||
|
Replace a tab's root controller then switch to that tab.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
tabBarController?.changeViewControllerToItem(withViewController: NewHome(), Item: 0)
|
||||||
|
```
|
||||||
|
|
||||||
|
### `class CustomTabBadge: UILabel`
|
||||||
|
The badge label type used above (`init(font:)`).
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>UIApplication</b> — environment, app info, open URL</summary>
|
||||||
|
|
||||||
|
### `enum Environment` + `static var inferredEnvironment: Environment`
|
||||||
|
`.debug` / `.testFlight` / `.appStore`, inferred from build config, simulator, and
|
||||||
|
the provisioning/receipt files.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
if UIApplication.inferredEnvironment == .appStore { enableAnalytics() }
|
||||||
|
```
|
||||||
|
|
||||||
|
### `static var displayName: String?` / `static var buildNumber: String?` / `static var version: String?`
|
||||||
|
Bundle info values. (`LCEssentials.appVersion` etc. forward to these.)
|
||||||
|
|
||||||
|
### `static func openURL(urlStr: String)`
|
||||||
|
Open a URL string if it can be opened.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
UIApplication.openURL(urlStr: "https://loverde.com.br")
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>UIResponder</b></summary>
|
||||||
|
|
||||||
|
### `var getParentViewController: UIViewController?`
|
||||||
|
Walk the responder chain to the owning view controller.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
someView.getParentViewController?.present(alert, animated: true)
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary><b>UIDevice</b> — notch metrics, model name</summary>
|
||||||
|
|
||||||
|
### `static var topNotch: CGFloat` / `static var bottomNotch: CGFloat` / `static var hasNotch: Bool`
|
||||||
|
Safe-area top/bottom insets and whether the device has a notch / Dynamic Island.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
let headerY: CGFloat = UIDevice.hasNotch ? 44 : 20
|
||||||
|
```
|
||||||
|
|
||||||
|
### `var modelName: String`
|
||||||
|
Marketing name from the hardware identifier (`"iPhone 15 Pro"`, `"iPad Air (5th generation)"`, …); falls back to the raw identifier for unknown devices. Reads `SIMULATOR_MODEL_IDENTIFIER` on the simulator.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
UIDevice.current.modelName // "iPhone 16 Pro"
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
## Collections & Tables
|
## Collections & Tables
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user