### Basic Auto Layout Constraint with SnapKit Source: https://github.com/quintgao/gknavigationbarswift/blob/master/Example/Pods/SnapKit/README.md This example demonstrates how to add a view and set its constraints using SnapKit's DSL in Swift. Ensure SnapKit is imported. ```swift import SnapKit class MyViewController: UIViewController { lazy var box = UIView() override func viewDidLoad() { super.viewDidLoad() self.view.addSubview(box) box.snp.makeConstraints { (make) -> Void in make.width.height.equalTo(50) make.center.equalTo(self.view) } } } ``` -------------------------------- ### Install SnapKit with Carthage Source: https://github.com/quintgao/gknavigationbarswift/blob/master/Example/Pods/SnapKit/README.md Integrate SnapKit into your Xcode project using Carthage by specifying the dependency in your Cartfile. ```ogdl github "SnapKit/SnapKit" ~> 4.0.0 ``` -------------------------------- ### Install SnapKit with CocoaPods Source: https://github.com/quintgao/gknavigationbarswift/blob/master/Example/Pods/SnapKit/README.md Integrate SnapKit into your Xcode project using CocoaPods by specifying the pod in your Podfile. ```ruby source 'https://github.com/CocoaPods/Specs.git' platform :ios, '10.0' use_frameworks! target '' do pod 'SnapKit', '~> 4.0.0' end ``` -------------------------------- ### Install TZImagePickerController with CocoaPods Source: https://github.com/quintgao/gknavigationbarswift/blob/master/Example/Pods/TZImagePickerController/README.md Use this command to install the TZImagePickerController library using CocoaPods for iOS 8 and later. ```bash pod 'TZImagePickerController' ``` -------------------------------- ### Creating a Root Navigation Controller Source: https://github.com/quintgao/gknavigationbarswift/blob/master/README.md Instantiate a UINavigationController with a root view controller and enable the left-swipe push gesture by setting `gk_openScrollLeftPush` to true. This custom initializer simplifies the setup of the main navigation stack. ```swift let nav = UINavigationController(rootVC: GKMainViewController()) nav.gk_openScrollLeftPush = true // 开启左滑push ``` -------------------------------- ### Install TZImagePickerController for iOS 6/7 with CocoaPods Source: https://github.com/quintgao/gknavigationbarswift/blob/master/Example/Pods/TZImagePickerController/README.md Use this command to install a specific version of TZImagePickerController using CocoaPods for compatibility with iOS 6 and iOS 7. ```bash pod 'TZImagePickerController', '2.2.6' ``` -------------------------------- ### Global Navigation Bar Configuration Source: https://context7.com/quintgao/gknavigationbarswift/llms.txt Configure default navigation bar appearance globally in your AppDelegate. Call this once during app launch to set consistent styling across your entire application. Supports basic setup or custom configurations for various elements like background, title, back button, shadow, status bar, item spacing, and gesture sensitivity. ```swift // AppDelegate.swift import GKNavigationBarSwift func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Basic setup with default values (white background, black title) GKConfigure.setupDefault() // Or use custom configuration GKConfigure.setupCustom { configure in // Navigation bar appearance configure.backgroundColor = UIColor.systemBlue configure.titleColor = UIColor.white configure.titleFont = UIFont.boldSystemFont(ofSize: 18.0) // Back button style configure.backStyle = .white // .black, .white, or .none configure.backImage = UIImage(named: "custom_back") // Custom back image // Shadow line configure.lineHidden = false configure.lineColor = UIColor.lightGray // Status bar configure.statusBarStyle = .lightContent configure.statusBarHidden = false // Navigation bar item spacing configure.gk_navItemLeftSpace = 12.0 configure.gk_navItemRightSpace = 12.0 // Gesture sensitivity configure.gk_snapMovementSensitivity = 0.7 configure.gk_popTransitionCriticalValue = 0.5 configure.gk_pushTransitionCriticalValue = 0.3 // Global UIScrollView gesture handling configure.gk_openScrollViewGestureHandle = true // Auto-hide tabbar when pushing configure.gk_hidesBottomBarWhenPushed = true } return true } ``` -------------------------------- ### Setting Status Bar Style on Initialization Source: https://github.com/quintgao/gknavigationbarswift/blob/master/README.md Set the status bar style within the controller's initialization method to prevent potential flickering issues when switching view controllers. This ensures the status bar style is correctly applied from the start. ```swift override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) self.gk_statusBarStyle = .lightContent } ``` -------------------------------- ### Enable Gesture Handling for UIScrollView Source: https://context7.com/quintgao/gknavigationbarswift/llms.txt Enable gesture handling for individual UIScrollView instances to resolve conflicts with navigation pop gestures. This ensures smooth navigation when scroll views are at their content start position. ```swift import UIKit import GKNavigationBarSwift class ScrollViewController: UIViewController { private let scrollView = UIScrollView() private let tableView = UITableView() override func viewDidLoad() { super.viewDidLoad() // Enable gesture handling for individual scroll views scrollView.gk_openGestureHandle = true tableView.gk_openGestureHandle = true // Setup views scrollView.frame = view.bounds scrollView.contentSize = CGSize(width: view.bounds.width * 3, height: view.bounds.height) scrollView.isPagingEnabled = true view.addSubview(scrollView) } } // Alternatively, enable globally in configuration // GKConfigure.setupCustom { // configure.gk_openScrollViewGestureHandle = true // } ``` -------------------------------- ### Creating Navigation Controller Source: https://context7.com/quintgao/gknavigationbarswift/llms.txt Initialize a navigation controller with gesture handling support. Use the convenience initializers to enable full-screen pop gestures and optional scaling transition effects. You can also enable left-swipe to push functionality and control the scaling transition effect. ```swift import GKNavigationBarSwift // Basic navigation controller with gesture support let rootViewController = HomeViewController() let navigationController = UINavigationController(rootVC: rootViewController) // Navigation controller with scaling transition effect (like Toutiao app) let navWithScale = UINavigationController(rootVC: rootViewController, scale: true) // Enable left-swipe to push functionality navigationController.gk_openScrollLeftPush = true // Enable/disable scaling transition navigationController.gk_transitionScale = true // Set as window's root window?.rootViewController = navigationController window?.makeKeyAndVisible() ``` -------------------------------- ### Implement Custom Push and Pop Transitions Source: https://context7.com/quintgao/gknavigationbarswift/llms.txt Set custom push and pop transition animations per view controller for unique navigation experiences. Requires conforming to UIViewControllerAnimatedTransitioning. ```swift import UIKit import GKNavigationBarSwift class CustomTransitionViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Set custom push transition self.gk_pushTransition = FadeInTransition() // Set custom pop transition self.gk_popTransition = FadeOutTransition() } } // Custom fade transition example class FadeInTransition: NSObject, UIViewControllerAnimatedTransitioning { func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { return 0.35 } func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { guard let toView = transitionContext.view(forKey: .to) else { return } let containerView = transitionContext.containerView toView.alpha = 0 containerView.addSubview(toView) UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: { toView.alpha = 1 }) { _ in transitionContext.completeTransition(!transitionContext.transitionWasCancelled) } } } class FadeOutTransition: NSObject, UIViewControllerAnimatedTransitioning { func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { return 0.35 } func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { guard let fromView = transitionContext.view(forKey: .from), let toView = transitionContext.view(forKey: .to) else { return } let containerView = transitionContext.containerView containerView.insertSubview(toView, belowSubview: fromView) UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: { fromView.alpha = 0 }) { _ in transitionContext.completeTransition(!transitionContext.transitionWasCancelled) } } } ``` -------------------------------- ### Initialize TZImagePickerController and present it Source: https://github.com/quintgao/gknavigationbarswift/blob/master/Example/Pods/TZImagePickerController/README.md This Objective-C code initializes the TZImagePickerController with a maximum image count and a delegate. It then presents the picker view controller. You can optionally set a block to handle the selected photos. ```objective-c TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:9 delegate:self]; // You can get the photos by block, the same as by delegate. // 你可以通过block或者代理,来得到用户选择的照片. [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { }]; [self presentViewController:imagePickerVc animated:YES completion:nil]; ``` -------------------------------- ### Configure TZImagePickerController for Max/Min Video Length and Photo Size Source: https://github.com/quintgao/gknavigationbarswift/blob/master/Example/Pods/TZImagePickerController/README.md You can set maximum and minimum lengths for videos and minimum/maximum dimensions for photos. Assets that do not meet these requirements will not be displayed. For synchronous filtering, use `isAssetCanBeDisplayed`. For selection-time warnings, use `isAssetCanBeSelected`. ```swift let imagePickerVc = TZImagePickerController() imagePickerVc.maxImagesCount = 9 imagePickerVc.allowPickingVideo = true imagePickerVc.allowPickingImage = true imagePickerVc.allowTakeVideo = true imagePickerVc.allowPickingOriginalPhoto = true // To set max/min video length: // imagePickerVc.videoMaximumDuration = 60.0 // seconds // imagePickerVc.videoMinimumDuration = 5.0 // seconds // To set min/max photo dimensions (requires custom implementation in isAssetCanBeDisplayed): // imagePickerVc.photoWidth = 1000 // imagePickerVc.photoHeight = 1000 ``` -------------------------------- ### Default Navigation Configuration Source: https://github.com/quintgao/gknavigationbarswift/blob/master/README.md Add this line in your AppDelegate to set up the default navigation configuration for the application. This is a required step for initializing the library's core settings. ```swift GKConfigure.setupDefault() ``` -------------------------------- ### Implement Custom Asset Filtering Source: https://github.com/quintgao/gknavigationbarswift/blob/master/Example/Pods/TZImagePickerController/README.md To filter assets based on specific criteria (e.g., video duration, photo dimensions), implement the `isAssetCanBeDisplayed` method. This method is synchronous. For asynchronous information like video size or iCloud status, you'll need to modify the source code, which may impact album opening speed. ```swift // Example of implementing isAssetCanBeDisplayed (synchronous filtering): // func isAssetCanBeDisplayed(asset: PHAsset) -> Bool { // // Your filtering logic here // return true // } ``` -------------------------------- ### Implement GKViewControllerPopDelegate to Track Pop Progress Source: https://context7.com/quintgao/gknavigationbarswift/llms.txt Implement this protocol to receive callbacks during swipe-to-pop gestures. This is useful for coordinating animations or updating UI elements based on the gesture's progress. ```swift import UIKit import GKNavigationBarSwift class AnimatedViewController: UIViewController, GKViewControllerPopDelegate { private let overlayView = UIView() override func viewDidLoad() { super.viewDidLoad() // Assign self as pop delegate self.gk_popDelegate = self // Setup overlay for animation overlayView.frame = view.bounds overlayView.backgroundColor = UIColor.black.withAlphaComponent(0.5) overlayView.alpha = 0 view.addSubview(overlayView) } // MARK: - GKViewControllerPopDelegate // Called when pop gesture starts func viewControllerPopScrollBegan() { print("Pop gesture started") overlayView.alpha = 0.5 } // Called during pop gesture - track progress (0.0 - 1.0) func viewControllerPopScrollUpdate(progress: CGFloat) { print("Pop progress: \(progress)") // Fade overlay based on progress overlayView.alpha = 0.5 * (1 - progress) } // Called when pop gesture ends func viewControllerPopScrollEnded(finished: Bool) { if finished { print("Pop completed - view will disappear") } else { print("Pop cancelled - returning to original state") UIView.animate(withDuration: 0.25) { self.overlayView.alpha = 0 } } } } ``` -------------------------------- ### Implement GKViewControllerPushDelegate for Left Swipe to Push Source: https://context7.com/quintgao/gknavigationbarswift/llms.txt Implement this protocol to handle custom push transitions triggered by a left swipe. Assign the delegate and implement the required methods to define the push behavior. ```swift import UIKit import GKNavigationBarSwift class ArticleViewController: UIViewController, GKViewControllerPushDelegate { var nextArticle: Article? override func viewDidLoad() { super.viewDidLoad() // Assign self as push delegate self.gk_pushDelegate = self } // MARK: - GKViewControllerPushDelegate // Called when left swipe completes - create and push the next controller func pushToNextViewController() { guard let article = nextArticle else { return } let nextVC = ArticleViewController() nextVC.configure(with: article) navigationController?.pushViewController(nextVC, animated: true) } // Called when push gesture starts func viewControllerPushScrollBegan() { print("Push gesture started") // Prepare next view controller or fetch data } // Called during push gesture - track progress (0.0 - 1.0) func viewControllerPushScrollUpdate(progress: CGFloat) { print("Push progress: \(progress)") // Update UI based on progress (e.g., preview indicator) } // Called when push gesture ends func viewControllerPushScrollEnded(finished: Bool) { if finished { print("Push completed") } else { print("Push cancelled") } } } // Don't forget to enable left swipe push on the navigation controller // navigationController.gk_openScrollLeftPush = true ``` -------------------------------- ### Optimize Video Export Performance Source: https://github.com/quintgao/gknavigationbarswift/blob/master/Example/Pods/TZImagePickerController/README.md Video export involves two steps: obtaining an AVURLAsset (which can be slow for iCloud videos due to network requests) and saving the video to the sandbox. To provide user feedback for the slow first step, consider extracting the source code and implementing progress updates. ```swift // To provide progress for the first step (getting AVURLAsset): // 1. Copy the library's source code. // 2. Implement progress tracking for the asset fetching process. // 3. Display progress to the user. ``` -------------------------------- ### Awake GKConfigure on App Launch Source: https://github.com/quintgao/gknavigationbarswift/blob/master/README.md Call GKConfigure.awake() during application launch to resolve issues with awake methods not being automatically called in Xcode 11.4 during debugging. Note: Versions 1.4.6 and later may not require manual calling due to changes in loading timing. ```swift func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { GKConfigure.awake() } ``` -------------------------------- ### Obtain Image File Path for Uploads Source: https://github.com/quintgao/gknavigationbarswift/blob/master/Example/Pods/TZImagePickerController/README.md When uploading photos, do not rely on `PHImageFileURLKey` as it's not always available and only accessible via the Photos framework. If an upload requires a path, save the `UIImage` to the sandbox first and use the sandbox path. For a name parameter, use the image's original name. ```swift // To upload a photo by path: // 1. Save the UIImage to the sandbox. // let imageData = UIImage.pngData() // let filePath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .userDomainMask, true)[0] as NSString // let fullPath = filePath.stringByAppendingPathComponent("myImage.png") // imageData?.writeToFile(fullPath, atomically: false) // // 2. Use the fullPath for uploads. // // For a name parameter, use the image's original name. ``` -------------------------------- ### Configure Navigation Bar Appearance for TZImagePickerController Source: https://github.com/quintgao/gknavigationbarswift/blob/master/Example/Pods/TZImagePickerController/README.md When using TZImagePickerController, if navigation bar color settings are ineffective, especially with WRNavigationBar integrated, ensure TZImagePickerController's controllers are added to WRNavigationBar's blacklist. If WRNavigationBar is not used, search issues for similar problems or provide a reproducible demo. ```objective-c imagePickerVc.navigationBar.standardAppearance.configureWithOpaque background color:UIColor.whiteColor() foregroundColor:UIColor.blackColor() titleTextAttributes:nil imagePickerVc.navigationBar.scrollEdgeAppearance.configureWithOpaque background color:UIColor.whiteColor() foregroundColor:UIColor.blackColor() titleTextAttributes:nil ``` -------------------------------- ### Handle Asset Selection Constraints Source: https://github.com/quintgao/gknavigationbarswift/blob/master/Example/Pods/TZImagePickerController/README.md To prevent users from selecting assets that don't meet certain criteria (e.g., maximum number of photos), implement the `isAssetCanBeSelected` method. This method is called when the user attempts to select an asset. ```swift // Example of implementing isAssetCanBeSelected: // func isAssetCanBeSelected(asset: PHAsset) -> Bool { // // Check if the asset meets selection criteria // return true // } ``` -------------------------------- ### Configure Navigation Bar for Dark Mode Source: https://context7.com/quintgao/gknavigationbarswift/llms.txt Set navigation bar appearance for both light and dark modes with automatic switching support. Images for background, shadow, and back button can be customized per mode. ```swift import UIKit import GKNavigationBarSwift class DarkModeSupportViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() self.gk_navTitle = "Dark Mode Support" // Set light mode appearance self.gk_navBackgroundColor = UIColor.white self.gk_navBackgroundImage = UIImage(named: "nav_bg_light") self.gk_navShadowImage = UIImage(named: "nav_line_light") self.gk_backImage = UIImage(named: "back_black") // Set dark mode appearance (automatically used in dark mode) self.gk_darkNavBackgroundImage = UIImage(named: "nav_bg_dark") self.gk_darkNavShadowImage = UIImage(named: "nav_line_dark") self.gk_darkBackImage = UIImage(named: "back_white") } } // Global dark mode configuration // GKConfigure.setupCustom { // configure in // configure.backgroundImage = UIImage(named: "nav_bg_light") // configure.darkBackgroundImage = UIImage(named: "nav_bg_dark") // configure.lineImage = UIImage(named: "nav_line_light") // configure.darkLineImage = UIImage(named: "nav_line_dark") // configure.backImage = UIImage(named: "back_black") // configure.darkBackImage = UIImage(named: "back_white") // } ``` -------------------------------- ### Access Device Metrics and Safe Area Information Source: https://context7.com/quintgao/gknavigationbarswift/llms.txt Use these static methods to retrieve device-specific layout information. Ensure UIKit and GKNavigationBarSwift are imported. This code is typically used within a UIViewController's lifecycle methods. ```swift import UIKit import GKNavigationBarSwift class LayoutViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Navigation bar heights let navBarHeight = UIDevice.navBarHeight() // Without status bar let fullNavHeight = UIDevice.navBarFullHeight() // With status bar let portraitNavHeight = UIDevice.navBarFullHeightForPortrait() // Status bar heights let statusBarHeight = UIDevice.statusBarFullHeight() let portraitStatusBarHeight = UIDevice.statusBarHeightForPortrait() // Tab bar height let tabBarHeight = UIDevice.tabBarHeight() // Safe area insets let safeInsets = UIDevice.safeAreaInsets() // Screen detection let isNotched = UIDevice.isNotchedScreen // iPhone X and later let isDynamicIsland = UIDevice.isDynamicIslandScreen() // iPhone 14 Pro and later let isLandscape = UIDevice.isLandScape() // Device type let isIPad = UIDevice.isIPad let isIPhone = UIDevice.isIPhone let isMac = UIDevice.isMac // Mac Catalyst // Screen sizes let screenWidth = UIDevice.width let screenHeight = UIDevice.height // Liquid Glass support (iOS 26+) let isLiquidGlass = UIDevice.isLiquidGlass() // Example: Layout content below navigation bar let contentView = UIView() contentView.frame = CGRect( x: 0, y: fullNavHeight, width: view.bounds.width, height: view.bounds.height - fullNavHeight - tabBarHeight ) view.addSubview(contentView) } } ``` -------------------------------- ### Dynamic Status Bar Visibility Source: https://github.com/quintgao/gknavigationbarswift/blob/master/README.md Implement these methods in your base view controller to dynamically control the status bar's visibility. Ensure these are overridden in subclasses that require dynamic status bar behavior. ```swift override var prefersStatusBarHidden: Bool { return self.gk_statusBarHidden } override var preferredStatusBarStyle: UIStatusBarStyle { return self.gk_statusBarStyle } ``` -------------------------------- ### Intercept Navigation Pop Behavior in Swift Source: https://context7.com/quintgao/gknavigationbarswift/llms.txt Implement `GKGesturePopHandlerProtocol` to intercept and control navigation pop behavior for both button clicks and swipe gestures. Return `true` to allow the pop action. ```swift import UIKit import GKNavigationBarSwift class EditViewController: UIViewController { var hasChanges = false override func viewDidLoad() { super.viewDidLoad() self.gk_navTitle = "Edit Profile" } // Called for both button clicks and gestures // Return true to allow pop, false to prevent override func navigationShouldPop() -> Bool { if hasChanges { showUnsavedChangesAlert() return false } return true } // Optional: Control only gesture-based pop func navigationShouldPopOnGesture() -> Bool { return !hasChanges } // Optional: Control only button click pop func navigationShouldPopOnClick() -> Bool { if hasChanges { showUnsavedChangesAlert() return false } return true } // Optional: Handle gesture conflicts (e.g., with WKWebView) func popGestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { // Return true to allow both gestures to work simultaneously return true } private func showUnsavedChangesAlert() { let alert = UIAlertController( title: "Unsaved Changes", message: "You have unsaved changes. Do you want to discard them?", preferredStyle: .alert ) alert.addAction(UIAlertAction(title: "Cancel", style: .cancel)) alert.addAction(UIAlertAction(title: "Discard", style: .destructive) { [weak self] _ in self?.hasChanges = false self?.navigationController?.popViewController(animated: true) }) present(alert, animated: true) } } ``` -------------------------------- ### Adding Custom Navigation Bar Button Items Source: https://context7.com/quintgao/gknavigationbarswift/llms.txt Add custom left and right bar button items to the navigation bar using factory methods. Supports images, titles, custom colors, and fonts. ```swift import UIKit import GKNavigationBarSwift class SettingsViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() self.gk_navTitle = "Settings" // Single right bar button with image self.gk_navRightBarButtonItem = UIBarButtonItem.gk_item( image: UIImage(named: "icon_more"), target: self, action: #selector(moreButtonTapped) ) // Single right bar button with title self.gk_navRightBarButtonItem = UIBarButtonItem.gk_item( title: "Save", color: UIColor.systemBlue, font: UIFont.systemFont(ofSize: 16), target: self, action: #selector(saveButtonTapped) ) // Multiple right bar buttons let searchItem = UIBarButtonItem.gk_item( image: UIImage(named: "icon_search"), target: self, action: #selector(searchTapped) ) let shareItem = UIBarButtonItem.gk_item( image: UIImage(named: "icon_share"), target: self, action: #selector(shareTapped) ) self.gk_navRightBarButtonItems = [shareItem, searchItem] // Custom left bar button (replaces back button) self.gk_navLeftBarButtonItem = UIBarButtonItem.gk_item( title: "Cancel", color: UIColor.red, target: self, action: #selector(cancelTapped) ) // Bar button with image and custom color let coloredItem = UIBarButtonItem.gk_item( image: UIImage(named: "icon_star"), color: UIColor.systemYellow, target: self, action: #selector(starTapped) ) self.gk_navRightBarButtonItem = coloredItem } @objc func moreButtonTapped() { print("More tapped") } @objc func saveButtonTapped() { print("Save tapped") } @objc func searchTapped() { print("Search tapped") } @objc func shareTapped() { print("Share tapped") } @objc func cancelTapped() { navigationController?.popViewController(animated: true) } @objc func starTapped() { print("Star tapped") } } ``` -------------------------------- ### Control Status Bar Appearance in Swift Source: https://context7.com/quintgao/gknavigationbarswift/llms.txt Set the status bar style and visibility per view controller. Ensure to override `prefersStatusBarHidden` and `preferredStatusBarStyle` for dynamic changes. ```swift import UIKit import GKNavigationBarSwift class DarkModeViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = UIColor.black // Set status bar style self.gk_statusBarStyle = .lightContent // Hide status bar self.gk_statusBarHidden = false } // REQUIRED: Override these methods for dynamic status bar changes override var prefersStatusBarHidden: Bool { return self.gk_statusBarHidden } override var preferredStatusBarStyle: UIStatusBarStyle { return self.gk_statusBarStyle } // Toggle status bar visibility func toggleStatusBar() { self.gk_statusBarHidden = !self.gk_statusBarHidden } // Change status bar style dynamically func setLightStatusBar() { self.gk_statusBarStyle = .lightContent } func setDarkStatusBar() { if #available(iOS 13.0, *) { self.gk_statusBarStyle = .darkContent } else { self.gk_statusBarStyle = .default } } } ``` -------------------------------- ### Handle Video Export Issues with TZImagePickerController Source: https://github.com/quintgao/gknavigationbarswift/blob/master/Example/Pods/TZImagePickerController/README.md For video export failures, upgrade to version 2.2.6 or later. This version defaults to not correcting video orientation, which can resolve issues with videos from Android devices. If orientation correction is needed, set `needFixComposition` to YES, but be aware of potential failures with Android videos. Refer to the issue for more details. ```swift let imagePickerVc = TZImagePickerController() imagePickerVc.needFixComposition = true // Set to true if orientation correction is required, but be cautious with Android videos. ``` -------------------------------- ### Dynamic Navigation Bar Transparency on Scroll Source: https://context7.com/quintgao/gknavigationbarswift/llms.txt Implement transparency effects for the navigation bar that change based on scroll position. Useful for detail pages with header images. Ensure the view controller conforms to UIScrollViewDelegate. ```swift import UIKit import GKNavigationBarSwift class ScrollDetailViewController: UIViewController, UIScrollViewDelegate { private let scrollView = UIScrollView() private let headerHeight: CGFloat = 250 override func viewDidLoad() { super.viewDidLoad() // Start with transparent navigation bar self.gk_navBarAlpha = 0.0 self.gk_navBackgroundColor = UIColor.white self.gk_navLineHidden = true self.gk_navTitle = "Photo Detail" // Setup scroll view scrollView.delegate = self scrollView.frame = view.bounds scrollView.contentSize = CGSize(width: view.bounds.width, height: 1500) view.addSubview(scrollView) // Add header image view let headerView = UIImageView(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: headerHeight)) headerView.image = UIImage(named: "header_bg") headerView.contentMode = .scaleAspectFill scrollView.addSubview(headerView) } func scrollViewDidScroll(_ scrollView: UIScrollView) { let offsetY = scrollView.contentOffset.y // Calculate alpha based on scroll offset var alpha: CGFloat = 0 if offsetY > 0 { alpha = min(1.0, offsetY / (headerHeight - 88)) } // Update navigation bar transparency self.gk_navBarAlpha = alpha // Change title color based on alpha self.gk_navTitleColor = alpha > 0.5 ? .black : .white // Change back button style based on background self.gk_backStyle = alpha > 0.5 ? .black : .white // Show shadow line when fully opaque self.gk_navLineHidden = alpha < 1.0 } } ``` -------------------------------- ### Per-Controller Navigation Bar Customization Source: https://context7.com/quintgao/gknavigationbarswift/llms.txt Customize the navigation bar appearance for individual view controllers. Each property automatically triggers the navigation bar to update when set. This includes setting the title, background color or image, title styling, shadow line, back button image and style, transparency, and more. ```swift import UIKit import GKNavigationBarSwift class DetailViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // MARK: - Navigation Bar Customization // Set navigation bar title self.gk_navTitle = "Detail Page" // Or use custom title view let titleLabel = UILabel() titleLabel.text = "Custom Title" titleLabel.textColor = .white self.gk_navTitleView = titleLabel // Background color self.gk_navBackgroundColor = UIColor.systemIndigo // Or use background image self.gk_navBackgroundImage = UIImage(named: "nav_bg") // Title styling self.gk_navTitleColor = UIColor.white self.gk_navTitleFont = UIFont.boldSystemFont(ofSize: 20) // Shadow line self.gk_navShadowColor = UIColor.gray self.gk_navLineHidden = false // Show/hide shadow line // Custom back button image self.gk_backImage = UIImage(named: "white_back") self.gk_backStyle = .white // .black, .white, .none // Navigation bar transparency (0.0 - 1.0) self.gk_navBarAlpha = 1.0 } // Hide/show shadow line dynamically func toggleShadowLine() { self.hideNavLine() // Hide self.showNavLine() // Show } } ``` -------------------------------- ### Control Swipe-to-Pop Gestures in Swift Source: https://context7.com/quintgao/gknavigationbarswift/llms.txt Manage swipe-to-pop gesture behavior per view controller. Options include disabling gestures, enabling edge-only pop, or customizing the swipe distance. ```swift import UIKit import GKNavigationBarSwift class FormViewController: UIViewController { var hasUnsavedChanges = false override func viewDidLoad() { super.viewDidLoad() // Disable all pop gestures self.gk_interactivePopDisabled = true // Or disable full-screen pop, keep edge pop only self.gk_fullScreenPopDisabled = true // Set maximum distance from left edge for pop gesture (in points) self.gk_maxPopDistance = 100 // Disable system gesture handling (for custom transitions) self.gk_systemGestureHandleDisabled = false } // Enable/disable gestures based on form state func updateGestureState() { if hasUnsavedChanges { self.gk_interactivePopDisabled = true } else { self.gk_interactivePopDisabled = false } } } ``` -------------------------------- ### Setting Navigation Bar Background Color Source: https://github.com/quintgao/gknavigationbarswift/blob/master/README.md Set the background color of the navigation bar by assigning a UIColor to the `gk_navBackgroundColor` property. This property is available immediately after calling it, creating the navigation bar if it doesn't exist. ```swift self.gk_navBackgroundColor = [UIColor red] ``` -------------------------------- ### Fix Navigation Bar Issues with GKNavigationBarViewController Source: https://github.com/quintgao/gknavigationbarswift/blob/master/Example/Pods/TZImagePickerController/README.md If the navigation bar disappears when using GKNavigationBarViewController, ensure the library is updated to version 2.0.4 or later. Refer to the provided issue link for detailed information. ```swift import GKNavigationBarViewController // Ensure GKNavigationBarViewController is updated to 2.0.4 or later ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.