VTMagic is a page container library for iOS.

Related tags

Table View VTMagic
Overview

VTMagic

VTMagic is a page container library for iOS, you can custom every page controller by different identifier if you need. It's so easy to use!(中文手册传送门

CHANGELOG(变更日志)

preview image

Communication

  • If you found a bug, and can provide steps to reliably reproduce it, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Installation

CocoaPods

VTMagic is available through CocoaPods. To install it, simply add the following line to your Podfile, and then import <VTMagic/VTMagic.h>:

pod "VTMagic"

Manually

  1. Download the project and drop VTMagic folder into your project.
  2. Import file VTMagic.h.
#import "VTMagic.h"

Requirements

This library requires iOS 6.0+ and Xcode 7.0+.

Usage

To run the example project, clone the repo, and run pod install from the project directory first.

Integration

- (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;
}

or like this

#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];
}

Protocols

You must conform to <VTMagicViewDataSource>. <VTMagicViewDelegate> and <VTMagicReuseProtocol> are optional.

VTMagicViewDataSource

- (NSArray<NSString *> *)menuTitlesForMagicView:(VTMagicView *)magicView {
    return _menuList;
}

- (UIButton *)magicView:(VTMagicView *)magicView menuItemAtIndex:(NSUInteger)itemIndex {
    static NSString *itemIdentifier = @"itemIdentifier";
    UIButton *menuItem = [magicView dequeueReusableItemWithIdentifier:itemIdentifier];
    if (!menuItem) {
        menuItem = [UIButton buttonWithType:UIButtonTypeCustom];
        [menuItem setTitleColor:RGBCOLOR(50, 50, 50) forState:UIControlStateNormal];
        [menuItem setTitleColor:RGBCOLOR(169, 37, 37) forState:UIControlStateSelected];
        menuItem.titleLabel.font = [UIFont fontWithName:@"Helvetica" size:16.f];
    }
    return menuItem;
}

- (UIViewController *)magicView:(VTMagicView *)magicView viewControllerAtPage:(NSUInteger)pageIndex {
    if (0 == pageIndex) {
        static NSString *recomId = @"recom.identifier";
        VTRecomViewController *recomViewController = [magicView dequeueReusablePageWithIdentifier:recomId];
        if (!recomViewController) {
            recomViewController = [[VTRecomViewController alloc] init];
        }
        return recomViewController;
    }

    static NSString *gridId = @"grid.identifier";
    VTGridViewController *gridViewController = [magicView dequeueReusablePageWithIdentifier:gridId];
    if (!gridViewController) {
        gridViewController = [[VTGridViewController alloc] init];
    }
    return gridViewController;
}

VTMagicViewDelegate

- (void)magicView:(VTMagicView *)magicView viewDidAppear:(UIViewController *)viewController atPage:(NSUInteger)pageIndex {
    NSLog(@"pageIndex:%ld viewDidAppear:%@", (long)pageIndex, viewController.view);
}

- (void)magicView:(VTMagicView *)magicView viewDidDisappear:(UIViewController *)viewController atPage:(NSUInteger)pageIndex {
    NSLog(@"pageIndex:%ld viewDidDisappear:%@", (long)pageIndex, viewController.view);
}

- (void)magicView:(VTMagicView *)magicView didSelectItemAtIndex:(NSUInteger)itemIndex {
    NSLog(@"didSelectItemAtIndex:%ld", (long)itemIndex);
}

VTMagicReuseProtocol

This method will be called when page is reused, you should clear old data or reset content offset in here.

- (void)vtm_prepareForReuse {
    NSLog(@"clear old data if needed:%@", self);
}

Features

Appearance callbacks

VTMagic will automatically calls the appearance callbacks when user switches the page, maybe you should do something in here, e.g. refresh page info.

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    // do something...
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    // do something...
}

Get magicController

You can get the nearest magicController in any child view controller which is conforms to <VTMagicProtocol>, after you import file VTMagic.h.

NSInteger currentPage = self.magicController.currentPage;
UIViewController *viewController = self.magicController.currentViewController;

Switch to specified page

You can switch to some specified page.

[self.magicView switchToPage:3 animated:YES];
[self.magicController switchToPage:3 animated:YES];

Get specified view controller

You can get any page controller by page index, it will return nil if the page is not on the screen.

UIViewController *viewController = [self.magicView viewControllerAtPage:3];
UIViewController *viewController = [self.magicController viewControllerAtPage:3];

Author

VictorTian email: [email protected]

License

VTMagic is released under the MIT license. See LICENSE for details.

Comments
  • UIColor+Magic.h VTColorZero编译问题

    UIColor+Magic.h VTColorZero编译问题

    我们项目封装了一个UIKit组件,这个组件依赖VTMagic,这样使用会报编译错误。目前还不知道具体原因。

    我发现VTColorZero只有一个地方在用,是否可以将static const VTColor VTColorZero;这句代码移动到VTColorIsZero函数里面呢?如下所示。

    CG_INLINE BOOL
    VTColorIsZero(VTColor aColor)
    {
        static const VTColor VTColorZero;
        return VTColorIsEqual(VTColorZero, aColor);
    }
    

    snip20160809_6 snip20160809_7

    opened by henshao 12
  • 滑动的时候pageIndex不准确

    滑动的时候pageIndex不准确

    • (UIViewController *)magicView:(VTMagicView *)magicView viewControllerAtPage:(NSUInteger)pageIndex { NSLog(@"Index = %zi",pageIndex); static NSString *gridId = @"grid.identifier"; VTGridViewController *viewController = [magicView dequeueReusablePageWithIdentifier:gridId]; if (!viewController) { viewController = [[VTGridViewController alloc] init]; } viewController.menuInfo = menuInfo; return viewController; }

    当在ScrollView中来回多滑动几次的时候,你会发现PageIndex的值就不准了,望修复这个bug,谢谢!

    opened by qqcc1388 2
  • VTMagicController生命周期 统计问题

    VTMagicController生命周期 统计问题

    当在外层VTMagicView里的子VC(VC1,不与currentPage相邻)嵌套一个里层VTMagicView(需要切换到VC2,不与currentPage相邻,且位于靠后的位置)时,通过click Menu的方式,先点击VC1(防止preload),再滑动Menu到最后,此时会触发VTMagicController的viewWillDisappear方法,导致appearanceState = VTAppearanceStateWillDisappear,然后再通过click Menu的方式,点击VC2,发现VC2的viewDidAppear方法不会执行,原因VTMagicView的shouldForwardAppearanceMethods方法里,只有在appearanceState为VTAppearanceStateDidAppear或者VTAppearanceStateWillAppear才会触发。希望能及时修复这个问题,非常感谢!!! Xcode版本14.0,iOS版本16.0。

    opened by witwql 0
  • 在 VTMagic 控制器中 修改 navigationBar 的 BarTintColor 无效

    在 VTMagic 控制器中 修改 navigationBar 的 BarTintColor 无效

    在 push 到 VTMagic 控制器中的 修改 navigationBar 的 BarTintColor 如下

    • (void)viewWillAppear:(BOOL)animated { [super viewWillAppear: animated]; [self.navigationController.navigationBar setBarTintColor: [UIColor blueColor]]; } 并没有改变 在 viewDidAppear 中可以改变,但是颜色的切换变得生硬。 请问这个问题是如何产生的,如何处理,谢谢
    opened by qyfeng009 1
  • Xcode 11.3 UITableView:Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy

    Xcode 11.3 UITableView:Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy

    VTMagic[6333:1035842] [TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it until the table view has been added to a window. Table view: <UITableView: 0x1060be200; frame = (0 0; 375 603); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x282a10f30>; layer = <CALayer: 0x2824449c0>; contentOffset: {0, 0}; contentSize: {375, 2200}; adjustedContentInset: {0, 0, 49, 0}; dataSource: <_UIFilteredDataSource: 0x282a17e40>>

    opened by include11 2
Owner
Victor Tian
Victor Tian
A Swift library for swipeable table cells

BWSwipeRevealCell Using the library **Note: Use version 1.0.1 for Swift 2.3 support and version 2.0.0 or higher for Swift 3 support ** There are two m

Kyle Newsome 67 May 11, 2022
Objective-C library for drag-n-drop of UITableViewCells in a navigation hierarchy of view controllers.

ios-dragable-table-cells Support for drag-n-drop of UITableViewCells in a navigation hierarchy of view controllers. You drag cells by tapping and hold

Anders Borum 49 Aug 23, 2022
INTUZ is presenting an interesting a Multilevel Expand/Collapse UITableView App Control to integrate inside your native iOS-based application

INTUZ is presenting an interesting a Multilevel Expand/Collapse UITableView App Control to integrate inside your native iOS-based application. MultilevelTableView is a simple component, which lets you use the tableview with multilevel tree view in your project.

INTUZ 3 Oct 3, 2022
Simple static table views for iOS in Swift.

Simple static table views for iOS in Swift. Static's goal is to separate model data from presentation. Rows and Sections are your “view models” for yo

Venmo 1.3k Nov 19, 2022
An easy-to-use UITableViewCell subclass that implements a swippable content view which exposes utility buttons (similar to iOS 7 Mail Application)

SWTableViewCell An easy-to-use UITableViewCell subclass that implements a swipeable content view which exposes utility buttons (similar to iOS 7 Mail

Christopher Wendel 7.2k Dec 31, 2022
Networking layer implementation using CLEAN Architecture for iOS.

NetworkLayer-CLEANArchitecture Networking layer implementation using CLEAN Architecture for iOS. Features ✨ CLEAN Architecture ✨ No Storyboards No ext

Qazi Muhammad Shahood 0 Dec 24, 2021
TableViews - Emoji Table View For iOS With Swift

TableViews Hello! This is EmojiTableView. Let me introduce you my first app when

null 0 Jan 2, 2022
Reading animation allows you to click on the different page numbers and accordingly it will animate page changes in a cool way. It has a very attractive UI and is very easy to use.

Reading Animation Cool Reading Animation in iOS written in Swift. Preview Table of content :- Description How to add in your project Requirement Licen

MindInventory 42 Oct 4, 2022
A PageView Swiping to the left will go to previous page and swiping to the right will go to next page

PageView This package creates a PageView. Swiping to the left will go to previous page and swiping to the right will go to next page. You can find how

null 0 Oct 20, 2021
A library that provides the ability to import/export Realm files from a variety of data container formats.

Realm Converter Realm Converter is an open source software utility framework to make it easier to get data both in and out of Realm. It has been built

Realm 212 Dec 9, 2022
Useful SwiftUI container view's. FittingGeometry, ScrollableView, LayoutReader, PageView, UIKitView. (iOS)

Containers Also available as a part of my SwiftUI+ Collection – just add it to Xcode 13+ Useful SwiftUI container view's for additional convenience. I

SwiftUI+ 32 Dec 27, 2022
ViperServices - Simple dependency injection container for services written for iOS in swift supporting boot order

ViperServices Introduction ViperServices is dependency injection container for iOS applications written in Swift. It is more lightweight and simple in

Siarhei Ladzeika 5 Dec 8, 2022
iPages 📖 Quickly implement swipable page views in iOS

iPages ?? Quickly implement swipable page views in iOS. ?? Get Started | Examples | Customize | Install | Get Started Install iPages Add iPages to you

Benjamin Sage 169 Dec 25, 2022
How to develop an iOS 14 application with SwiftUI 2.0 framework. How to create an Onboarding Screen with Page Tab View

Ama-Fruits USER INTERFACE AND USER EXPERIENCE APP DESIGN How to develop an iOS 14 application with SwiftUI 2.0 framework. How to create an Onboarding

Noye Samuel 1 Dec 11, 2021
This page contains an iOS Application that uses Modelplace.AI Cloud API

Modelplace iOS App This page contains an iOS Application that uses Modelplace.AI

OpenCV.AI 7 Jan 21, 2022
LinkedIn-Profile - UI of Android LinkedIn App Profile Page in iOS SwiftUI

LinkedIn-Profile UI of Android LinkedIn App Profile Page in iOS SwiftUI Sample I

null 0 Feb 4, 2022
Meet Page View Controller for iOS by Cleveroad

While a standard page view allows you to navigate between pages by using simple gestures, our component goes further

Cleveroad 397 Aug 20, 2022
Deli is an easy-to-use Dependency Injection Container that creates DI containers

Deli is an easy-to-use Dependency Injection Container that creates DI containers with all required registrations and corresponding factories.

Jungwon An 134 Aug 10, 2022
Dip is a simple Dependency Injection Container.

Dip is a simple Dependency Injection Container. It's aimed to be as simple as possible yet p

Olivier Halligon 949 Jan 3, 2023
RxReduce is a lightweight framework that ease the implementation of a state container pattern in a Reactive Programming compliant way.

About Architecture concerns RxReduce Installation The key principles How to use RxReduce Tools and dependencies Travis CI Frameworks Platform Licence

RxSwift Community 125 Jan 29, 2022