gpt4 book ai didi

ios - UITabBar 中带有 SideMenu 的问题

转载 作者:行者123 更新时间:2023-11-29 12:15:04 25 4
gpt4 key购买 nike

我在 objective-c 中以编程方式创建了标签栏 Controller ,我需要实现侧边栏菜单。是否可以在标签栏 Controller 中实现侧边栏菜单?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
// Override point for customization after application launch.
self.tabBarController =[[UITabBarController alloc]init];
//Initialize View controller and speciality
UIViewController *viewcontroller1=[[HomeView alloc]init];
UIViewController *viewcontroller2=[[Speciality alloc]init];
UIViewController *viewcontroller3=[[Activity alloc]init];
UIViewController *viewcontroller4 =[[Notification alloc]init];
UIViewController *viewcontroller5 =[[Profile alloc]init];
self.tabBarController.viewControllers=[NSArray arrayWithObjects:viewcontroller1,viewcontroller2,viewcontroller3,viewcontroller4,viewcontroller5, nil];
self.window.rootViewController =self.tabBarController;
self.tabBarController.tabBar.barTintColor = [UIColor colorWithRed:0.376 green:0.729 blue:0.318 alpha:1.000];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}

最佳答案

下载库 https://github.com/John-Lluch/SWRevealViewController

并将文件 SWRevealViewController.hSWRevealViewController.m 复制到您的项目

AppDelegate.h

#import "SWRevealViewController.h"

@property (strong,nonatomic) SWRevealViewController *revealViewController;

AppDelegate.m

self.revealViewController = [[SWRevealViewController alloc]initWithRearViewController:leftViewController frontViewController:tabBarController];
if ( self.revealViewController )
{
UIButton *button1 = [[UIButton alloc]initWithFrame:CGRectMake(8, 65, 80, 30)];
[button1 setTitle:@"Side bar" forState:UIControlStateNormal];
[button1 setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[button1 addTarget:self.revealViewController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];
[tabBarController.view addSubview:button1];//if u hav navigation controller u can replace button1 with BarButtonItem
[tabBarController.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
}

关于ios - UITabBar 中带有 SideMenu 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32221388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com