wangmchn / wmpagecontroller Goto Github PK
View Code? Open in Web Editor NEWAn easy solution to page controllers like NetEase News
License: MIT License
An easy solution to page controllers like NetEase News
License: MIT License
感觉一滚动 ,就在不停调用layoutChildViewControllers,做了很多没意思的操作啊,这个该怎么优化呢?
how to set a parameter ?
我想在顶部菜单栏底部加一条分割线,目前加不上去。我是尝试在WMPageController初始化的时候加一个view到menuView,可是此时menuView为空。我尝试在viewDidiLoad中加但也是空的。
建议把这里修改为:
- (void)menuView:(WMMenuView *)menu didSelesctedIndex:(NSInteger)index currentIndex:(NSInteger)currentIndex {
NSInteger gap = (NSInteger)labs(index - currentIndex);
animate = NO;
CGPoint targetP = CGPointMake(viewWidth*index, 0);
[self.scrollView setContentOffset:targetP animated:gap > 1?NO:self.pageAnimatable];
_selectIndex = (int)index;
UIViewController *vc = [self.displayVC objectForKey:@(_selectIndex)];
if (vc == nil) {
// 先从 cache 中取
vc = [self.memCache objectForKey:@(_selectIndex)];
if (vc) {
// cache 中存在,添加到 scrollView 上,并放入display
[self addCachedViewController:vc atIndex:_selectIndex];
self.currentViewController = vc;
} else {
// cache 中也不存在,创建并添加到display
[self addViewControllerAtIndex:_selectIndex];
self.currentViewController = self.displayVC[@(_selectIndex)];
}
} else {
self.currentViewController = vc;
}
if (gap > 1 || !self.pageAnimatable) {
[self postFullyDisplayedNotificationWithCurrentIndex:(int)index];
// 由于不触发 -scrollViewDidScroll: 手动清除控制器..
UIViewController *vc = [self.displayVC objectForKey:@(currentIndex)];
if (vc) {
[self removeViewController:vc atIndex:currentIndex];
}
}
}
当初始化进去后,viewDidLoad 实现[self addViewControllerAtIndex:self.selectIndex]; 当前index 的view frame为nil,而- (void)viewDidLayoutSubviews后也没对index 的view frame进行更新。 所以要对index view 进行赋值,以便后面进行更新,修改如下:
// 添加子控制器
- (void)addViewControllerAtIndex:(int)index {
Class vcClass = self.viewControllerClasses[index];
UIViewController *viewController = [[vcClass alloc] init];
[self addChildViewController:viewController];
viewController.view.frame = [self.childViewFrames[index] CGRectValue];
[viewController didMoveToParentViewController:self];
[self.scrollView addSubview:viewController.view];
[self.displayVC setObject:viewController forKey:@(index)];
self.currentViewController = viewController;
[self backToPositionIfNeeded:viewController atIndex:index];
}
i wanna set wmmenuview as titleview,but i notice that if you push to another viewcontroller,after pull back,the wmmenuview will increase more subviews.
i check the thread stack finded that the reason is when push viewcontroller,the parent controller will call "willMoveToSuperview" again,so the wmmenuview will add new items,but obversely you dont want that happen.
so a simple way to fix the problem is to add a bool variable and add a if control,like below:
works fine on me.hope will help somebody
我的工程的首页就是这种控制器, 但是菜单的栏目是从网络获取的, 而我的APP一启动就直接显示首页, 请问我要怎么处理?
新闻样式
譬如MenuView在导航栏上的样式
请加我qq176999955
你在WMPageController.m中的viewDidLoad方法中有这么一句话self.edgesForExtendedLayout = UIRectEdgeNone;这样子controller的view就不能全屏显示了哦。我在WMPageController中的calculateSize方法里面添加了这么一句代码
if (self.edgesForExtendedLayout == UIRectEdgeAll) {
_viewY = self.viewFrame.origin.y + 64.0f;
}
今天偶然间发现了你的控件,特地下下来玩了一下,发现了一点小问题,就是当用手势滑动的时候,调用了slideMenuAtProgress:方法更新UI,但是并没有在其中设置item的selected,虽然不影响大局,但是这个selected属性在拓展的时候经常会用到,可能修复一下会比较好。
快速左右滑動Controller
點擊 status bar 發現 Scroll to top 會沒反應
有个页面是需要登录才能展示的, 但是滚动的时候代理并不会被触发,有什么好的解决办法么?
我目前是在viewWillAppear 里面判断,如果未登录就手动设置menu选中上个页面.
我想的是可否增加一个选项:
将要展示某个页面时,根据代理返回的bool值 决定是否展示.
我现在遇到的问题是:WMPageController现在在某个Index 比如0. 切换到app的其他地方做了一些操作后,需要跳转到WMPageController的页面的0 index. 我通过设置self.pageView.selectIndex = 0;后调到了对应的index 但是页面是空白的页面。 网络请求的数据是正确的。
有没有人遇到类似的情况?
(void)viewDidLoad {
[super viewDidLoad];
WMPageController *pageController = [self getDefaultController];
pageController.title = @"Line";
}
(WMPageController *)getDefaultController{
NSMutableArray *viewControllers = [[NSMutableArray alloc] init];
NSMutableArray *titles = [[NSMutableArray alloc] init];
for (int i = 0; i < 4; i++) {
Class vcClass;
NSString *title;
switch (i % 3) {
case 0:
vcClass = [YZViewController class];
title = @"Greetings";
break;
case 1:
vcClass = [YZSales_VC class];
title = @"Hit Me";
break;
default:
vcClass = [YZViewController class];
title = @"Fluency";
break;
}
[viewControllers addObject:vcClass];
[titles addObject:title];
}
WMPageController *pageVC = [[WMPageController alloc] initWithViewControllerClasses:viewControllers andTheirTitles:titles];
pageVC.pageAnimatable = YES;
pageVC.menuItemWidth = 85;
pageVC.postNotification = NO;
return pageVC;
}
设置了没啥反应
App间跳转会导致未显示的ChildViewController被销毁
能否添加这样一个代理方法,在外界捕获到滑动的时候,获得到当前选中的索引。
请问如何在实例化的时候给controller传值
因为tab页 , 结构都一样只是 参数不一样 ,我想在实例化的时候传入参数!!
望解答,谢谢,辛苦了。。。
我的项目里,当显示WMPageController时,Navigation Bar 的颜色会变成亮灰色,而我的项目所有其他部分都是白色。我尝试在WMPageController初始化时设置view的背景颜色为白色也是无效。
Navigation Bar的颜色是在切换动画完成后改变的,也就是动画之中颜色还是正常,一旦动画结束颜色就变成亮灰了。
这个问题在你的demo里也能看到,只是变化是反的,切换过程中是亮灰,切换完毕变成白色。
Without this setting, I cannot support scroll to top gesture. And the scrollView property of WMMenuView
is private which cannot be modified.
Thanks.
如果我想要在程序启动后就显示这种界面,而不是通过导航控制器push过去,要怎么做呢,小白求教
可以考虑一下缓存之类的,让已经加载的controller重用之类.
看好多新闻类的app都好像缓存了一样.
要是能做到这个,那就是真正好用的轮子了
// 添加子控制器
我想问下每次都自动init,那我如果想在ib或者sb里面加载怎么办。。
正在使用你的 WMPageController, 但是我发现它的init方法用的是添加class的方法, 现在我想实现从当前控制器向WMPageController管理的其中一个控制器传值, 想了好久都没有解决方法, 故此请教,望回复
人比较笨,没明白,你说pageController进行传递数据,可是这个没法改变WMViewControlle或者WMTableViewController或者WMCollectionViewController里面的 数据类型 假如这里面的数据是根据外面传入的数据进行改变的,这个应该怎么办?by the way,你的这个写的是我看到的类似控件,用起来最简单的一个控件,非常方便!!!
就是reload后,view显示不了。盲点view里面button,跳转到另一个界面,再返回,才能显示。说明view加载了,就是显示不了
因为有时候我要传递一些参数给我的子controller,比如我只有initWithXXX:(XXX)aaa这样子的初始化方法,aaa可能是我从服务器获取的值
关于你的PageController 我想禁止手势滑动
我在你的WMPageController 的 addScrollView 方法中加入 scrollView.scrollEnabled = NO; 可以实现效果
但是如果外部调用pageController.scrollview.scollEnable =NO;却无法实现,想请教一下
In my case, I need to show a number in the item title, and update them at some times.
It seems that currently there is no method to update the title easily?
For fixed width items it should be easily to be updated since no frame recalculation is needed?
为什么我在我的项目中使用这些代码,在每次切换菜单的时候都会调用viewDidLayoutSubviews,导致menu每次都从0重新滚动一遍。而你的demo却没有,我自己做个实验,新建一个空白 的项目只放一个uiscrollview 每次向这个scrollview添加view的时候都会调用 viewDidLayoutSubviews。
真心很奇怪
通过设置values和keys向子控制器传值。(内部利用KVC实现)
我想在上面放一张图片 下面放选项卡 应该怎么改位置
子控制器界面内容较多时,第一次滑动过去的时候会停顿一下,当子控制器加载完毕后就左右滑动得很流畅了,所以我想问一下,能否实现预加载左右n页的功能,然后左右滑动的时候就流畅滑动无停顿
menuView 到下面的scrollView可以加个间隔字段
it calls the method:addMenuView when I scroll , and go to below lines:
then in the WMMenuView.m:
-(void)selectItemAtIndex:(NSInteger)index {
there is a delegate method @selector(menuView:didSelesctedIndex:currentIndex:), it will send to its delegate and responds to it. _animate will become NO, the bug comes:when I scroll again, the menuView couldn't add its view, cause in the method below:
it works well when I delete some delegate codes in the WMMenuView.m: - (void)selectItemAtIndex:(NSInteger)index:
// if ([self.delegate respondsToSelector:@selector(menuView:didSelesctedIndex:currentIndex:)]) {
// [self.delegate menuView:self didSelesctedIndex:index currentIndex:currentIndex];
// }
is it?
item 点击 item多了,会造成卡顿现象
Please support - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
in iOS 9.
每次都会把之前的ViewController给destroy掉,然后再次查看,重新进入viewdidload。都是些本地数据的话,不影响,但如果是通过网络获取数据或者是之前的viewcontroller内有输入框(处于编辑状态),这样的情况,重新加载整个视图,我觉得不是很合理~
如题。UIWebView这种可以横向scroll的view在配合使用的时候不知道怎么处理delegate比较好?
看上去不错啊,赞一个!
(void)menuView:(WMMenuView _)menu didSelesctedIndex:(NSInteger)index currentIndex:(NSInteger)currentIndex {
NSInteger gap = (NSInteger)labs(index - currentIndex);
_selectIndex = (int)index;
_animate = NO;
CGPoint targetP = CGPointMake(_viewWidth_index, 0);
[self.scrollView setContentOffset:targetP animated:gap > 1 ? NO : self.pageAnimatable];
if (gap > 1 || !self.pageAnimatable) {
// 由于不触发 -scrollViewDidScroll: 手动处理控制器
UIViewController *currentViewController = self.displayVC[@(currentIndex)];
// 最好判断一下,因为在做某个项目时,currentViewController = nil
if (currentViewController) {
[self removeViewController:currentViewController atIndex:currentIndex];
}
[self layoutChildViewControllers];
self.currentViewController = self.displayVC[@(self.selectIndex)];
[self postFullyDisplayedNotificationWithCurrentIndex:(int)index];
#pragma mark - 这里 是不是应该是 index 而不是 currentIndex
[self didEnterController:self.currentViewController atIndex: currentIndex];
}
感谢你提供这么好用的框架,但是我在实际使用过程中发现 第一个控制器不走viewDidAppear 或 will 方法.
请问是我参数设置的问题吗?
我尝试在已经有的控制器添加进去
代码是这样的
WMPageController *pageController = [self p_defaultController];
pageController.menuViewStyle = WMMenuViewStyleLine;
pageController.titleSizeSelected = 15;
[self.MainView addSubview:pageController.view];
能看到导航条,但是看不到内容
有个奇怪的问题,内容会在加载的一瞬间出现一次,然后就不见了
我断点去加载发现这样直接加载view的话,你控制器的viewDidLayoutSubviews不会调用,导致scrollview的frame为0
虽然这样但是却也出现一闪而过的内容页,比较疑惑,请问这种情况应该如何解决,谢谢~
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.