我想把它放在UIbutton
底部,它应该显示在我的所有视图上,比如tabBar onclick
,UIButton
我想打开菜单视图,如何实现这个功能,我为此做了很多尝试,也做了很多谷歌搜索,但没有提到正确实现这一目标的方法,所以请建议我实现这一目标的正确方法
问问题
1224 次
2 回答
2
我之前通过在 Appdelegate 类中添加一个按钮来完成此操作。我不知道这是否是正确的方法,但它正在工作。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
viewController = [[SUSAViewController alloc] initWithNibName:@"SUSAViewController" bundle:nil];
nav=[[UINavigationController alloc]initWithRootViewController:viewController];
self.window.rootViewController = nav;
UIButton *mybtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
mybtn.frame=CGRectMake(40, 200, 200, 200);
[mybtn setTitle:@"My Button" forState:UIControlStateNormal];
[nav.view addSubview:mybtn];
[self.window makeKeyAndVisible];
return YES;
}
如果您不使用,NavigationController
则只需添加[self.window addSubview:mybtn];
希望它对您有用。
于 2012-12-17T06:54:38.127 回答
0
您是否尝试过创建仅包含该按钮及其菜单项的 BaseViewController?
然后,如果您让所有视图控制器都从该 BaseViewController 继承,那么您的所有视图控制器都将具有该按钮。
// import your custom menu view
#import "CustomMenuView.h"
@interface BaseViewController : UIViewController
{
UIButton *btnMenu;
CustomMenuView *customMenu;
}
@end
...
// Now tell your other view controllers to inherit from the base view controller
#import "BaseViewController.h"
@interface YourOtherViewController: BaseViewController
{
}
@end
使用继承,你所有的视图控制器现在应该有那个按钮和菜单。
于 2012-12-17T08:50:20.993 回答