有两种解决方案,
您可以将全局菜单添加到 AppDelegate,
- (BOOL)应用程序:(UIApplication *)应用程序 didFinishLaunchingWithOptions:(NSDictionary *)launchOption
然后您可以将全局菜单添加到导航控制器视图中,例如,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.viewController = [[HomeViewController alloc] initWithNibName:nil bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.navigationController.delegate = self.viewController;
self.window.rootViewController = self.navigationController;
// Your Global Menu
UIButton *myButton ...
[self.navigationController.view addSubview:myButton];
[self.window makeKeyAndVisible];
return YES;
}
- 您可以创建一个 BaseViewController,并将全局按钮添加到 BaseViewController。然后所有其他视图控制器都继承 BaseViewController。所以一些视图控制器可能有全局菜单。如果某些视图控制器不需要全局菜单,只需继承普通的 UIViewController。
如,
#import "GlobalMenuView.h"
@interface BaseViewController : UIViewController
{
UIButton *btnMenu;
GlobalMenuView *globalMenu;
}
@end
然后想要全局菜单的视图控制器就可以了,
#import "BaseViewController.h"
@interface YourOtherViewController: BaseViewController
{
}
@end