我在ios应用程序中使用了pagemenu视图,方法是https://github.com/uacaps/PageMenu
在menuviewcontroller中我有一个导航栏,左侧有我的slidemenu按钮,右侧有条形按钮项目(我在故事栏中添加了选择的照片)
在该导航栏下方,我添加了pagemenu view 4标签(包含患者,EMR,聊天,处方)
所以根据点击我想隐藏/显示栏按钮项目(这意味着只有EMR标签我想显示栏按钮项目(选择照片)否则我想隐藏(提醒3个标签),但我无法实现它 这是我在menuviewcontroller viewdidload方法
中的代码- (void)viewDidLoad {
[super viewDidLoad];
SWRevealViewController *revealViewController = self.revealViewController;
if ( revealViewController )
{
[self->_slideOutMenu setTarget: self.revealViewController];
[self->_slideOutMenu setAction: @selector( revealToggle: )];
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
Patient* controller1 = [sb instantiateViewControllerWithIdentifier:@"patient"];
controller1.title = @"PATIENT";
EMR* controller2 = [sb instantiateViewControllerWithIdentifier:@"emr"];
controller2.title = @"EMR";
Chat* controller3 = [sb instantiateViewControllerWithIdentifier:@"chatViewcontroller"];
controller3.title = @"CHAT";
Prescription* controller4 = [sb instantiateViewControllerWithIdentifier:@"prescription"];
controller4.title = @"PRESCRIPTION";
NSArray *controllerArray = @[controller1, controller2, controller3, controller4];
NSDictionary *parameters = @{
CAPSPageMenuOptionScrollMenuBackgroundColor: [UIColor colorWithRed:60.0/255.0 green:169.0/255.0 blue:128.0/255.0 alpha:1.0],
CAPSPageMenuOptionViewBackgroundColor: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
CAPSPageMenuOptionSelectionIndicatorColor: [UIColor whiteColor],
CAPSPageMenuOptionBottomMenuHairlineColor: [UIColor colorWithRed:70.0/255.0 green:70.0/255.0 blue:70.0/255.0 alpha:1.0],
CAPSPageMenuOptionMenuItemFont: [UIFont fontWithName:@"HelveticaNeue" size:12.0],
CAPSPageMenuOptionMenuHeight: @(70.0),
CAPSPageMenuOptionMenuItemWidth: @(120.0),
CAPSPageMenuOptionCenterMenuItems: @(YES)
};
_pagingMenuView = [[CAPSPageMenu alloc] initWithViewControllers:controllerArray frame:CGRectMake(0.0, 42.0, self.view.frame.size.width, self.view.frame.size.height-38) options:parameters];
if (_currentIndex >= 0 && _currentIndex <= 2){
[_pagingMenuView moveToPage:_currentIndex];
}
[self.view addSubview:_pagingMenuView.view];
}
查看我附上的截图
所以我想为emr选项卡以外的所有选项卡隐藏右侧导航栏按钮 viewdidload和viewwill出现在menuviewcontroller中的方法只被调用一次,那些不是每次都在调用菜单(病人,EMR,聊天,处方),所以我不知道如何实现它 请任何人帮我这个
提前致谢
这对我来说是这个问题中已接受的答案
添加此行
pagingMenuViewController.delegate=self;
在对象(pagingMenuViewController)之后启动
pagingMenuViewController = [[CAPSPageMenu alloc] initWithViewControllers:controllerArray frame:CGRectMake(0.0, 42.0, self.view.frame.size.width, self.view.frame.size.height-38) options:parameters];
self.navigationItem.rightBarButtonItem.tintColor=[UIColor clearColor];
pagingMenuViewController.delegate=self;
我添加了这个代表 CAPSPageMenuDelegate ansd委托方法
- (void)didMoveToPage:(UIViewController *)controller index:(NSInteger)index {
if(index ==1){
[self show];
}else{
[self hide];
}
}
- (void)willMoveToPage:(UIViewController *)controller index:(NSInteger)index{
if(index ==1){
[self show];
}else{
[self hide];
}
}
答案 0 :(得分:2)
在viewDidLoad方法中添加
_pagingMenuView.delegate = self
然后实现委托方法
- (void)didMoveToPage:(UIViewController *)controller index:(NSInteger)index {
if(index ==1){
self.navigationItem.rightBarButtonItem = //your barButton to select photo
self.navigationItem.leftBarButtonItem = nil;
}else{
self.navigationItem.rightBarButtonItem = nil;
self.navigationItem.leftBarButtonItem = //your barButton to reveal the slide menu
}
}
答案 1 :(得分:2)
确保在创建实例
后分配委托属性_pagingMenuView.delegate = self
其他隐藏,显示您可以在委托方法中处理的业务
答案 2 :(得分:1)
//将此代码粘贴到导航栏类
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(playerStatus:) name:@"hideNavigationButton" object:nil];
- (void) playerStatus:(NSNotification *) notification
{
// hide navigation button.
}
//When you tap the button call this method
[[NSNotificationCenter defaultCenter]postNotificationName:@"hideNavigationButton" object:nil];