Code Monkey home page Code Monkey logo

vtmagic's Introduction

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.

vtmagic's People

Contributors

lfarah avatar tianzhuo112 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vtmagic's Issues

内存在加载中有点高!

6个item的滑动。内存300M,会提示
2016-06-20 00:04:54.840 TestApp[4903:1922472] Received memory warning.

//我的tableview已经优化了的。

手势冲突

VTMagic滑动切换controller和tableview中cell左滑删除有冲突应该如何处理

参考demo,滚动的时候缓存数据

在disappear 里面保存,在setMenuinfo 里面去读取本地数据,顺带判断时间是否满足一小时,调试发现,当我有五个栏目的时候,左右滑动,只能保存一次数据。在save 和load 本地数据的时候,menuID 并不是当前展示的ID

VTMagic

VTMagic目录下的文件没有更新吧,我没有用pods

与滑动返回冲突

第一项向右滑动不能触发系统默认的滑动返回,应该是手势冲突了,有没有办法解决一下?

缓存问题

比如页面都是一样的,数据不一样,只能给每个页面加一个标识ID,不能只创建一个控制器,

Manual Installation

CocoaPods and Carthage are awesome tools and make our life really easier, but there are some devs who still don't know how to use them.

It would be cool to add the Manual installation guide in your README.md. You can take a look at my iOS Readme Template to see how you can do it.

可以成为页面的一部分吗

比如 手机上半部分是播放窗口,但是下面分为 简介、目录、评论三个segment页面,用你这个轮子实现

滑动的时候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,谢谢!

底部TabBar的问题

我在真机上运行Demo后,发现每当按住Home按键回到后台,然后再次进入程序后,TabBar的颜色会一开始是黑色,然后恢复系统的白色。原因是什么呢?

关于app进入后台问题

NSCache 进入后台之后会清空,如果viewcontroller个数大于三个,后台到前台之后就要重新创建viewcontroller,这个有办法解决么,我看网易不会这样

隐藏菜单

请教一下,如果想完全隐藏菜单栏(如图,红色框),如何做?谢谢
123

设置默认显示的页面

这个能不能设置默认显示到 第几页。
我现在是通过switchToPage 切换到想要默认显示的页面, 但是第一页的数据已经被加载了。

提供是否预加载下一个页面的开关

麻烦作者提供下是否预加载下一个页面的开关,或者取出预加载的功能.
有些页面用户在使用的时候可能不会去点击, 所有点击都预加载下一个页面,没有太多必要,会浪费用户流量.也会增加接口服务器的负担.

提两个建议

没仔细看代码,不过框架做的非常不错!

1.通过左右滑动,选中某个index需要单独做一个delegate。
2.顶部的bar,能否做成具有blur模糊效果,同时顶部有insets穿透效果。

我想问一下怎么设置magicView的frame

我想问一下怎么设置magicView的frame .h里好像没有类似的接口或者属性可以设置啊,如果我从别的界面push到这个magicview 那么上一个界面的导航栏就把magic上面的nav给遮住了。。。。

关于子控制器View的预览问题

默认是会预览控制器View的,可以增加关闭选项吗?现在默认进去后第一个和第二个控制器的view都加载完毕了。
snip20160617_51

[改进]切换menubar开关动画做成可选项

代码是必有动画的:

- (void)updateMenuBarWhenSwitchEnd
{
    _menuBar.needSkipLayout = NO;
    [UIView animateWithDuration:0.25 animations:^{
        [_menuBar updateSelectedItem:YES];
        [self updateMenuBarState];
    }];
}

可以加个选项么?正好遇到这样的需求...

所有页面的数据会同时加载

我的每一个ViewController都是独立的,结果一点击到一个基础页面哪里,他所有的页面数据都会加载,请问有办法点击到那个页面在加载数据吗?是说所有都要从基础页面加载数据传递过去吗

可以添加粘滞菜单的效果么?

在上方添加一个header 在向上滑动的时候类似Tableview的粘滞效果 header隐藏 menu到顶部之后粘滞在屏幕顶部~~~可以实现这种效果么?大致需要做哪些修改~~~

保存数据和滑动位置

如果滑动超过3页,要保存每一个曾经打开的table的数据和离开时滑动过的位置,是否只能记录下contentoffset属性,在恢复时候再滑动到之前的位置

求教如何改变headerHeight的高度值以及菜单布局疑惑

现在我看高度是在初始化中写死的64, headerHeight属性暴露出来了,但是赋值好像没用~~~~

大致五六个选项时候 用默认的选项布局时候4s是正常的,6plus的选项菜单如果没占满屏宽的时候会整体偏左,没有居中;用等分的布局模式6plus的显示可以正常,但是4s的屏宽不够会导致按钮中的部分字显示不完全,会省略掉一部分~

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

混编问题

你好
我想要在swift工程中使用这个库
pod的是1.2.3版本
在桥接文件中导入了库的头文件
2016-08-04 17 19 52

而在使用时,两种方式都不行
2016-08-04 17 21 48
2016-08-04 17 23 05

然后,我在你们关闭的问题中发现,是有人在swift中使用这个库的,那么是因为版本的问题么?
麻烦有时间帮忙看看。
谢谢!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.