父子控制器出现的问题

产生的问题

解决的办法

import "ViewController.h"

import "MRTabCollectionVC.h"

define ScreenSize ([UIScreen mainScreen].bounds.size)

import "MRMoveCollectionVC.h"

@interface ViewController ()
@property (nonatomic ,weak)MRTabCollectionVC *tempVC;
@property (nonatomic ,weak)MRMoveCollectionVC *TwoVC;
@end
....
@implementation ViewController

  • (void)viewDidLoad {
    [super viewDidLoad];
    //解决tableView 被 UIStatusBar 和 UITabbar 遮盖的问题
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.edgesForExtendedLayout = UIRectEdgeNone;
    }

-(void)setUI{
MRTabCollectionVC *vc = [[ MRTabCollectionVC alloc] init];
[self addChildViewController:vc];
self.tempVC = vc;
vc.collectionView.frame = CGRectMake(0, 80, ScreenSize.width, 60);
[self.view addSubview:vc.collectionView];
vc.collectionView.contentInset = UIEdgeInsetsMake(0, 20, 0,20);

 [vc didMoveToParentViewController:self];

MRMoveCollectionVC *vcTwo = [[ MRMoveCollectionVC alloc] init];
[self addChildViewController:vcTwo];
self.TwoVC = vcTwo;

vcTwo.collectionView.frame = CGRectMake(0, 280, ScreenSize.width, 300);
[self.view addSubview:vcTwo.collectionView];
[vcTwo didMoveToParentViewController:self];

self.tempVC.mrDelegate = self.TwoVC;

}

pragma 关闭 appearence callbacks自动调用的特性,改为手动

-(BOOL)shouldAutomaticallyForwardAppearanceMethods{
return NO;
}
//这个是重点!!!
//这个是重点!!!
//这个是重点!!!
//一定要在这个方法里 添加子控制器 在viewDidLoad 里面会出现太多的问题 包括1 tabbar和navagationbar对 子控制器管理的collectionView内的item 影响的问题 2 子控制器 背景色设置没用的问题 (抱歉 ,现在我还不知道如何解释这个问题)
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self setUI];

[self.tempVC beginAppearanceTransition:YES  animated:animated];
[self.TwoVC beginAppearanceTransition:YES  animated:animated];

}

-(void)viewDidAppear:(BOOL)animated{

[super viewDidAppear:animated];
 [self.tempVC endAppearanceTransition];
 [self.TwoVC endAppearanceTransition];

}

-(void)viewWillDisappear:(BOOL)animated{

[super viewWillDisappear:animated];
[self.tempVC beginAppearanceTransition:YES  animated:animated];
[self.TwoVC beginAppearanceTransition:YES  animated:animated];    

}
-(void)viewDidDisappear:(BOOL)animated{

[super viewDidDisappear:animated];
[self.tempVC endAppearanceTransition];
[self.TwoVC endAppearanceTransition];

}

  • (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

@end
...

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容