[英]MVYSideMenu pop to root viewcontroller
我在我的應用程序中使用MVYSideMenu ,我可以使用MVYSideMenu的“changeContentViewController”呈現新的控制器,但它提供了新的控制器,所以從這里我想回彈到我的根(HomeViewController)所以我已經做了很多關於此的研究但是沒有'找到解決方案。
所以,如果有人知道解決方案,請幫助我。 提前致謝。
當您嘗試打開任何視圖時, MVYSideMenu正在創建rootViewController
。 如果你正在創建rootViewController
,那么你就無法從中pop
。
因此,如果您想要返回,那么您必須Push
該視圖而不是生成rootViewController。
我想,現在您正在使用以下代碼打開側面菜單的任何控制器:
ChildViewController *contentVC = [[ChildViewController alloc] initWithNibName:@"ChildViewController" bundle:nil];
appDelegate.nav = [[UINavigationController alloc] initWithRootViewController:contentVC];
appDelegate.nav.navigationBarHidden=TRUE;
[[self sideMenuController] changeContentViewController:appDelegate.nav closeMenu:YES];
所以請使用以下代碼而不是上面的代碼。 這里nav是AppDelegate
中UINavigationController
對象。
ChildViewController *contentVC = [[ChildViewController alloc] initWithNibName:@"ChildViewController" bundle:nil];
[appDelegate.nav pushViewController:contentVC animated:YES];
[[self sideMenuController] changeContentViewController:appDelegate.nav closeMenu:YES];
因此,您可以從側面菜單中推送任何視圖。 而現在只是嘗試彈出這個視圖。 我相信你可以在使用它之后彈出這個視圖。
確保,如果你這樣做,那么可能存在內存泄漏。 因為viewControllers一直在添加到導航控制器。 所以我的建議是,如果你能說服你的客戶,不要這樣做。 :)否則,你必須自己制作側面菜單。
編輯: -
是的,我們可以為某些視圖控制器啟用/禁用側面菜單。 請將以下方法添加到MVYSideMenuController.m文件中。 並從viewControllers的viewWillAppear
調用此方法。
- (void)addGestures {
if (!_panGesture) {
_panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
[_panGesture setDelegate:self];
// [self.view addGestureRecognizer:_panGesture];
}
if (!_tapGesture) {
_tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleMenu)];
[_tapGesture setDelegate:self];
[self.view addGestureRecognizer:_tapGesture];
}
}
- (void)removeGestures{
[self.view removeGestureRecognizer:_panGesture];
_panGesture = nil;
}
您可以輕松地將此方法LocalNotifications
。 可能已經存在addGestures
了。 您可以在控制器中需要時通過調用removeGestures
方法刪除手勢。 但是在刪除手勢后需要側邊菜單時不要忘記添加addGestures
。
希望,這是你正在尋找的。 任何關注都會回復給我。 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.