2017年7月1日
1.UIViewController 有时候 view不现实在导航栏下面
原因:导航栏可能透明,导致,从顶部开始
解决
self.edgesForExtendedLayout = UIRectEdgeNone; //导航栏设置为有透明度,设置view不被导航栏覆盖```
补充 如果导航栏不透明,而且又不像往下偏移
self.extendedLayoutIncludesOpaqueBars = YES;
2017年5月24日
1.删除子控制器
for (UIViewController *vc in self.childViewControllers) {
[vc removeFromParentViewController];
}
2.因为 view页面不能跳转,所以,你如果需要用到子控制器里面的跳转,需要添加[self addChildViewController:TCVC];
实现
-(void)addChildViewController
{
for (int i = 0; i < self.dataList.count; i++) {
DiscoverSunViewController *TCVC = [[DiscoverSunViewController alloc]init];
TCVC.disType = [(HuDisCanMatchButtonModel*)self.dataList[i] Id];
TCVC.delegate = self;
TCVC.view.frame = CGRectMake(width * i, 0, width, height);
[_scrollView addSubview:TCVC.view];
[self addChildViewController:TCVC];
}
}
// DiscoverSunViewController.h
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
HuDiscoverListModel *model = self.myList[indexPath.row];
HuDiscoverCourseDetailsViewController *details = [[HuDiscoverCourseDetailsViewController alloc]init];
details.courseId = model.Id;
[self.navigationController pushViewController:details animated:YES];
}
2017年4月11日
1.vc返回按钮过滤掉指定的页面
效果答题,进入分析界面,点击放回,不能返回到答题界面
![image.png](http://upload-images.jianshu.io/upload_images/3003454-261410b9c468be99.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
实现:
/**
当前页面点击返回按钮 过滤掉第一个指定类型的页面
@param curVc 当前页面
@param specialVc 过滤掉的指定页面
*/
-
(void)curVc:(UIViewController)curVc backPassSpecialVCClass:(NSString)specialVc;
{
NSArray *vcArray = curVc.navigationController.viewControllers;
NSInteger count = [vcArray count];BOOL needPassTestPracticeVC = NO;
if (count >= 2)
{
//倒数第二个开始,最后一个不要判断
NSInteger i = count - 2;
for( ; i > 0; i--)
{
UIViewController *vc = vcArray[i];
if ([vc isKindOfClass:[NSClassFromString(specialVc) class]]) {
needPassTestPracticeVC = YES;
break;
}
}if (needPassTestPracticeVC) { [curVc.navigationController popToViewController:[vcArray objectAtIndex:i - 1] animated:YES]; }else{ [curVc.navigationController popViewControllerAnimated:YES]; }
}
}
使用:
- (void)backClick
{
//如果前一个页面是答题HuTestPracticeViewController,
[HuConfigration curVc:self backPassSpecialVCClass:kHuTestPracticeViewController];
}
2017年2月23日
1.底部menuBar 隐藏和显示接口
/**
隐藏和打开底部meubar
@param vc 需要隐藏的页面
@param flag 是否隐藏, yes隐藏 no显示
*/
- (void)hideMenuBar:(UIViewController )vc withFlag:(BOOL)flag
{
UITabBarController CustemVc=(UITabBarController)vc.tabBarController;
if(flag){
if ([CustemVc isKindOfClass:[CustomMyViewController class]]) {
[(CustomMyViewController)CustemVc hiddenTabBar];
}else if ([CustemVc isKindOfClass:[TrainTabBarViewController class]]){
[(TrainTabBarViewController)CustemVc hiddenTabBar];
}
}else{
if ([CustemVc isKindOfClass:[CustomMyViewController class]]) {
[(CustomMyViewController)CustemVc showInTabBar];
}else if ([CustemVc isKindOfClass:[TrainTabBarViewController class]]){
[(TrainTabBarViewController*)CustemVc showInTabBar];
}
}
}
一般用法:
// HuTestPracticeViewController.m
(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[HuConfigration hideMenuBar:self withFlag:YES];
}(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[HuConfigration hideMenuBar:self withFlag:NO];
}
2017年1月18日
1.导航栏相关设置
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//导航透明
self.navigationController.navigationBar.translucent = YES;
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
//导航不透明
self.navigationController.navigationBar.translucent = NO;
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:nil];
}
![Paste_Image.png](http://upload-images.jianshu.io/upload_images/3003454-86aa5dc40adfa468.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
2017年1月10日
1.页面的push 和 pop(非模态)
HuSessionListViewController *controller = [[HuSessionListViewController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
// HuSessionViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(backClick)];
}
-(void)back:(UIButton *)backBtn
{
[self.navigationController popViewControllerAnimated:YES];
}
1.1
MessageCenterController *messageVc = [[MessageCenterController alloc]init];
UINavigationController * Nav = [[UINavigationController alloc]initWithRootViewController:messageVc];
[self.window.rootViewController presentViewController:Nav animated:YES completion:nil];
1.2
//回到主界面
loginViewController *loginVc = [[loginViewController alloc]init];
[[[[UIApplication sharedApplication]windows]objectAtIndex:0]setRootViewController:loginVc];
2.设置rootViewController, (图片控制器无法加载出来,原因根视图是loginViewController,该页面不一定每次都存在,已经消失了)
[[UIApplication sharedApplication].keyWindow setRootViewController:custom];
//这种是模态方式添加页面,会是loginViewController 一直是rootViewController,导致IM发送图片,无法弹出图片选择框(loginViewController,已经登录过就不需要创建了,会报whose view is not in the window hierarchy)
//[self presentViewController:custom animated:YES completion:nil];
3.返回到指定页面(非一级一级返回)
3.1跳转到第一个同类界面的前一个界面
/**
跳转到第一个同类界面的前一个界面
@param vc 当前类界面
*/
-
(void) backFromFirstKindPage:(UIViewController*)controller
{
NSArray *vcArray = controller.navigationController.viewControllers;
UIViewController *lastVc = nil;
for(int i = 0; i < [vcArray count]; i++)
{
UIViewController *vc = vcArray[i];
if ([vc isKindOfClass:[controller class]])
{
break;
}lastVc = vc;
}
if (lastVc) {
[controller.navigationController popToViewController:lastVc animated:YES];
}
}
使用:
pragma mark - PrivateFunction
- (void)backClick
{
[HuConfigration backFromFirstKindPage:self];
}
3.2也可以用下标的方式
[controller.navigationController popToViewController:[vcArray objectAtIndex:index] animated:YES];
viewControllers 数组日志
<__NSArrayI 0x6180000f6f00>(
<PersonalCenterViewController: 0x7fbe60e2a1a0>,
<HuSessionListViewController: 0x7fbe60e8ff90>,
<HuSessionViewController: 0x7fbe638435d0>,
<PatientIndexViewController: 0x7fbe63b175c0>,
<HuSessionViewController: 0x7fbe60cad2f0>,
<PatientIndexViewController: 0x7fbe60e2f320>,
<HuSessionViewController: 0x7fbe63898c30>,
<PatientIndexViewController: 0x7fbe60ccbf60>,
<HuSessionViewController: 0x7fbe60ccc540>,
<PatientIndexViewController: 0x7fbe60ed0300>,
<HuSessionViewController: 0x7fbe60f11640>,
<PatientIndexViewController: 0x7fbe60cf6c30>,
<HuSessionViewController: 0x7fbe60f13c90>
)
如果您发现本文对你有所帮助,如果您认为其他人也可能受益,请把它分享出去。