Earth.m
//设置手势
UITapGestureRecognizer *tapGesturREconginzer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[self addGestureRecognizer:tapGesturREconginzer];
- (void)handleTap:(UITapGestureRecognizer *)recoginzer
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"clicked" object:nil];
}
ViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidClicked) name:@"clicked" object:nil];
}
#pragma mark 控制器跳转方法
- (void)viewDidClicked
{
UIViewController *normalViewController = [[NormalEarthViewController alloc] init];
[self.navigationController pushViewController:normalViewController animated:YES];
}
//用完移除,避免内存泄露
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
NormalViewController.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//从Storyboard中加载一些控件(要勾选uesStoryBoardID)
UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
self = [story instantiateViewControllerWithIdentifier:@"NormalEarthViewController"];
}
return self;
}
1、先设置手势
2、去到根控制器中viewDidLoad接受手势发来通知,执行viewDidClicked方法,记得用完移除,避免内存泄露
3、去到所跳转的控制器,从Storyboard中加载一些控件(要勾选uesStoryBoardID)