VTMagic

repository·master·Indexed 23 days ago

https://github.com/tianzhuo112/vtmagic

An iOS page container library for creating custom page controllers with navigation bars, sliders, and reusable page/menu components. It supports various layout styles, bubble-style sliders, and zoom effects. Key features include the VTMagicController for integration, VTMagicViewDataSource for menu and page management, and tools for memory cache control and page index retrieval.

Tokens
3K
Snippets
6
Records
20
Agent score
83%

What's inside VTMagic

  1. Control pages and navigation in VTMagic

    master

    VTMagic provides several ways to interact with the current state and navigate between pages:

    • Switch to a page: Use switchToPage:animated: on either magicView or magicController.
    • Get current state: Access currentPage and currentViewController from the magicController (available in any child view controller conforming to VTMagicProtocol).
    • Get a specific page controller: Use viewControllerAtPage: on either magicView or magicController. It returns nil if the page is not currently on screen.
  2. Configure navigation bar layout styles

    master

    VTMagic supports several layout styles for the navigation bar:

    • Adaptive: Automatically adjusts to text width.
    • Equal Distribution: Automatically divides space equally.
    • Center Layout (VTLayoutStyleCenter): Introduced in 1.0.2, centers the navigation content.
    • Custom Width: Allows for manual width configuration.
  3. Integrate VTMagic into a ViewController

    master

    There are two ways to integrate VTMagic:

    1. As a child view controller

    Add a VTMagicController instance as a child of your existing view controller and add its view to the hierarchy.

    2. By subclassing VTMagicController

    Inherit directly from VTMagicController to use its built-in magicView property.

    // Method 1: Adding as a child
    - (void)viewDidLoad {
        [super viewDidLoad];
        [self addChildViewController:self.magicController];
        [self.view addSubview:_magicController.view];
        [_magicController.magicView reloadData];
    }
    
    - (VTMagicController *)magicController {
        if (!_magicController) {
            _magicController = [[VTMagicController alloc] init];
            _magicController.magicView.navigationColor = [UIColor whiteColor];
            _magicController.magicView.sliderColor = [UIColor redColor];
            _magicController.magicView.layoutStyle = VTLayoutStyleDivide;
            _magicController.magicView.switchStyle = VTSwitchStyleDefault;
            _magicController.magicView.navigationHeight = 40.f;
            _magicController.magicView.dataSource = self;
            _magicController.magicView.delegate = self;
        }
        return _magicController;
    }
    
    // Method 2: Subclassing
    #import "VTMagicController.h"
    
    @interface ViewController : VTMagicController
    @end
    
    @implementation ViewController
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.magicView.navigationColor = [UIColor whiteColor];
        self.magicView.sliderColor = [UIColor redColor];
        self.magicView.layoutStyle = VTLayoutStyleDefault;
        self.magicView.switchStyle = VTSwitchStyleDefault;
        self.magicView.navigationHeight = 40.f;
        self.magicView.dataSource = self;
        self.magicView.delegate = self;
        [self.magicView reloadData];
    }
    @end
  4. Configure menu bar styles and effects in VTMagic

    master

    VTMagic provides several properties to customize the appearance of the menu bar:

    • Layout Styles: Change the menu bar layout using layoutStyle. Supported styles include VTLayoutStyleCenter (added in 1.0.2).
    • Slider Style: Set sliderStyle to VTSliderStyleBubble to show a bubble in the menu bar (added in 1.1.0).
    • Slider Extension: Use sliderExtension to modify the slider (added in 1.2.0).
    • Zoom Effect: Set the itemScale property to add a zoom effect to menuItem during transitions (added in 1.2.1).
  5. Retrieve page index for a ViewController

    master

    Starting from version 1.2.3, you can retrieve the index of a specific page or the current page using the following methods:

    • pageIndexForViewController:: Returns the index for any given view controller.
    • vtm_pageIndex: A category method to quickly retrieve the index of the current page.
  6. Customize menuItem and sliderView widths via delegate methods

    master

    In version 1.2.4, you can customize the width of individual menu items and the slider view by implementing the following delegate methods. This replaces the deprecated VTLayoutStyleCustom enum style. To set a custom width for a specific index, use these methods:

    • itemWidthAtIndex:: Returns the width for the menuItem at a specific index.
    • sliderWidthAtIndex:: Returns the width for the sliderView at a specific index.
  7. Get the page index of a view controller in VTMagic 1.2.3+

    master

    In version 1.2.3, you can retrieve the index of a page controller using:

    • pageIndexForViewController:: Returns the pageIndex for any given page controller.
    • vtm_pageIndex: A category method that conveniently returns the pageIndex of the current page controller.