我正在使用3D Touch实现主屏幕快捷方式,并且运行良好,但是我目前的方式意味着当快捷方式将用户转到特定的视图控制器时,标签栏和导航栏将丢失.
这是我的代码:
func handleShortCutItem(shortcutItem: UIApplicationShortcutItem) -> Bool { var handled = false if let shortcutType = ShortcutType.init(rawValue: shortcutItem.type) { let rootViewController = window!.rootViewController switch shortcutType { case .Favourites: let storyboard = UIStoryboard(name: "Main",bundle: nil) let rootController = storyboard.instantiateViewControllerWithIdentifier("favourites") as! FavouritesTableViewController rootController.parkPassed = DataManager.sharedInstance.getParkByName(NSUserDefaults.standardUserDefaults().stringForKey("currentPark")!) self.window?.rootViewController = rootController self.window?.makeKeyAndVisible() handled = true } return handled }
这是右舷布局(指示FavouritesTableViewController):
编辑:
这是我更新的代码:
@available(iOS 9.0,*) func handleShortCutItem(shortcutItem: UIApplicationShortcutItem) -> Bool { var handled = false if let shortcutType = ShortcutType.init(rawValue: shortcutItem.type) { switch shortcutType { case .Favourites: print("favourites") let storyboard = UIStoryboard(name: "Main",bundle: nil) let rootController = storyboard.instantiateViewControllerWithIdentifier("favourites") as! FavouritesViewController rootController.parkPassed = DataManager.sharedInstance.getParkByName(NSUserDefaults.standardUserDefaults().stringForKey("currentPark")!) let root = UIApplication.sharedApplication().delegate as! AppDelegate if let navCont = root.window?.rootViewController?.navigationController { navCont.presentViewController(rootController,animated: true,completion: nil) } else { root.window?.rootViewController?.presentViewController(rootController,completion: nil) } root.window?.makeKeyAndVisible() handled = true } } return handled }
解决方法
尝试这个:
从应用程序委托获取代理:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
您想要从故事板中呈现的控制器:
Controller *cont=//get the reference from storyboard either using storyboard ID
然后让您的rootview显示另一个控制器:
[appDelegate.window.rootViewController presentViewController:cont animated:YES completion:^{ DLog(@"presented your view ON TOP of the tab bar controller"); }];
迅速:
var appDelegate: AppDelegate = UIApplication.sharedApplication().delegate() var cont: Controller = //get the reference form storyboard appDelegate.window.rootViewController.presentViewController(cont,completion: { DLog("presented your view ON TOP of the tab bar controller") })
你可以在主线程上移动演示内容,如果你喜欢!!!!