GKNavigationBarSwift

repository·master·Indexed 41 days ago

https://github.com/quintgao/gknavigationbarswift

A Swift-based iOS framework for highly customizable navigation bars. It provides non-intrusive, low-coupling solutions for custom styles, transition animations such as scale or left-swipe push, and gesture management including scroll view conflict resolution.

Tokens
3.3K
Snippets
13
Records
19
Agent score
52%

What's inside GKNavigationBarSwift

  1. Install TZImagePickerController

    master

    You can install TZImagePickerController using CocoaPods, Carthage, or manual installation.

    CocoaPods

    For iOS 8 and later:

    pod 'TZImagePickerController'

    For iOS 6 and 7:

    pod 'TZImagePickerController', '2.2.6'

    Carthage

    github "banchichen/TZImagePickerController"

    Manual Installation

    Drag the TZImagePickerController folder into your project and import the header:

    #import "TZImagePickerController.h"
    pod 'TZImagePickerController'
  2. Configure Root UINavigationController and Push Animations

    master

    When creating your root navigation controller, you can enable specific transition effects like the 'left-swipe push' (similar to NetEase News).

    let nav = UINavigationController(rootVC: GKMainViewController())
    nav.gk_openScrollLeftPush = true // Enables left-swipe push animation
  3. Initialize GKNavigationBarSwift in AppDelegate

    master

    To use the framework, you must first configure the default settings in your AppDelegate. This sets up the necessary infrastructure for the custom navigation bars.

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        GKConfigure.setupDefault()
        return true
    }
  4. Install SnapKit via CocoaPods

    master

    To integrate SnapKit into your Xcode project using CocoaPods, add the following to your Podfile. Note that CocoaPods 1.1.0+ is required for SnapKit 4.0.0+.

    source 'https://github.com/CocoaPods/Specs.git'
    platform :ios, '10.0'
    use_frameworks!
    
    target '<Your Target Name>' do
        pod 'SnapKit', '~> 4.0.0'
    end

    After updating your Podfile, run pod install in your terminal.

  5. Handle Dynamic Status Bar Styles

    master

    If you need to change the status bar style (e.g., light vs. dark) dynamically within a controller, you must override the following properties in your base controller class to link them to the framework's properties:

    override var prefersStatusBarHidden: Bool {
        return self.gk_statusBarHidden
    }
    
    override var preferredStatusBarStyle: UIStatusBarStyle {
        return self.gk_statusBarStyle
    }
  6. Configure info.plist permissions for TZImagePickerController

    master

    Because TZImagePickerController uses the Camera, Location, Microphone, and Photo Library, you must add the following keys to your info.plist file to avoid crashes or permission issues:

    • Privacy - Camera Usage Description
    • Privacy - Location Usage Description
    • Privacy - Location When In Use Usage Description
    • Privacy - Microphone Usage Description
    • Privacy - Photo Library Usage Description
  7. Prevent Status Bar Flickering

    master

    To avoid visual glitches (like the status bar appearing half-black/half-white) during controller transitions, always set the gk_statusBarStyle within the controller's init method.

    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        
        // Set the style in init to prevent flickering during transitions
        self.gk_statusBarStyle = .lightContent
    }
  8. Troubleshoot navigation bar color issues

    master

    If setting the navigation bar color is ineffective or it remains white, check the following:

    1. iOS 13+ Appearance: For versions 3.6.4 and above, you may need to configure imagePickerVc.navigationBar.standardAppearance as shown in the project Demo.
    2. WRNavigationBar Integration: If you are using WRNavigationBar, add the TZImagePickerController controllers to its wr_setBlackList to prevent it from overriding the picker's appearance.
    3. GKNavigationBar Integration: If you are using GKNavigationBarViewController, ensure you have upgraded to version 2.0.4 or higher.
  9. Use TZImagePickerController to pick photos

    master

    Initialize TZImagePickerController with a maximum image count and a delegate. You can retrieve the selected photos using either the delegate pattern or a completion block.

    To use the block-based approach for retrieving photos, use setDidFinishPickingPhotosHandle:.

    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:9 delegate:self];
    
    // You can get the photos by block, the same as by delegate.
    [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
        // Handle selected photos here
    }];
    
    [self presentViewController:imagePickerVc animated:YES completion:nil];