如何使用ios中的选项卡制作滑动菜单 [英] How to make sliding menu with tabs in ios

查看:164
本文介绍了如何使用ios中的选项卡制作滑动菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ZUUIRevealController库。

I am using ZUUIRevealController Library.

Appdelegate.h文件

(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window = window;

     UITabBarController *tabBarController=[[UITabBarController alloc]init];

    FrontViewController *frontViewController = [[FrontViewController alloc] init];
    RearViewController *rearViewController = [[RearViewController alloc] init];
    MapViewController *frontViewController2 = [[MapViewController alloc] init];

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
    UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:frontViewController2];


    RevealController *revealController = [[RevealController alloc] initWithFrontViewController:navigationController rearViewController:rearViewController];

    RevealController *revealController2 = [[RevealController alloc] initWithFrontViewController:navigationController2 rearViewController:rearViewController];


    [revealController.tabBarItem setTitle:@"Home"];
    [revealController2.tabBarItem setTitle:@"Absent note"];



    revealController.tabBarItem.image=[[UIImage imageNamed:@"home_icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    revealController2.tabBarItem.image=[[UIImage imageNamed:@"absent_note_icon.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];





    [tabBarController setViewControllers:[NSArray arrayWithObjects:revealController,revealController2,nil]];



    [self.window setRootViewController:tabBarController];

    [self.window makeKeyAndVisible];
    return YES;
}

FrontViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.title = NSLocalizedString(@"Front View", @"FrontView");

    if ([self.navigationController.parentViewController respondsToSelector:@selector(revealGesture:)] && [self.navigationController.parentViewController respondsToSelector:@selector(revealToggle:)])
    {
        UIPanGestureRecognizer *navigationBarPanGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self.navigationController.parentViewController action:@selector(revealGesture:)];
        [self.navigationController.navigationBar addGestureRecognizer:navigationBarPanGestureRecognizer];
        [self.view addGestureRecognizer:navigationBarPanGestureRecognizer];

        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Slide", @"Slide") style:UIBarButtonItemStylePlain target:self.navigationController.parentViewController action:@selector(revealToggle:)];

        }








}

RearViewController是一个Table ViewController

MapViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.title = NSLocalizedString(@"Map View", @"MapView");

    if ([self.navigationController.parentViewController respondsToSelector:@selector(revealGesture:)] && [self.navigationController.parentViewController respondsToSelector:@selector(revealToggle:)])
    {
        UIPanGestureRecognizer *navigationBarPanGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self.navigationController.parentViewController action:@selector(revealGesture:)];
        [self.navigationController.navigationBar addGestureRecognizer:navigationBarPanGestureRecognizer];
        [self.view addGestureRecognizer:navigationBarPanGestureRecognizer];

        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Slide", @"Slide") style:UIBarButtonItemStylePlain target:self.navigationController.parentViewController action:@selector(revealToggle:)];
    }
}

标签工作正常,但滑动菜单无法正常工作。

Tabs working Properly, but the sliding menu not working properly.

首先我点击Home选项卡和Slide菜单查看幻灯片Viewcontroller.Next我点击了Second选项卡和滑动菜单来查看幻灯片Viewcontroller。我再次点击了Home选项卡和滑动菜单来查看Slide Viewcontroller。它不能显示只显示黑屏。

First I am click the Home tab and Slide menu to view the slide Viewcontroller.Next I clicked the Second tab and sliding menu to view the slide Viewcontroller. Again I've clicked the Home tab and sliding menu to view the Slide Viewcontroller. It cannot displayed only display a black screen.

推荐答案

我找到了解决该问题的方法。 Appdelegate文件中的
我已经编写了swreavealtoggle调用导航。

I found the solution for that problem. in Appdelegate file i have written the swreavealtoggle call for navigation.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;

HomeViewController *frontViewController = [[HomeViewController alloc] init];
SlideViewController *rearViewController = [[SlideViewController alloc] init];


UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];

SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
revealController.delegate = self;
self.viewController = revealController;

[self.window setRootViewController:self.viewController];
[self customizeInterface];
[self.window makeKeyAndVisible];
return YES;}

然后创建一个viewController来添加Tabbar项目组件。
Myviewcontroller名称为HomeViewController.h
包含标签项按钮后单击操作

Then create a viewController to add a Tabbar item components. Myviewcontroller name is HomeViewController.h after i include the tab item button click action

#import <UIKit/UIKit.h>
@interface HomeViewController : UIViewController<UITabBarDelegate>{
UITabBar *mainTabBar;
UIViewController *tab1vc;  // view controller of first tab
UIViewController *tab2vc;  // view controller of second tab
UIViewController *tab3vc;  // view controller of first tab
UIViewController *tab4vc;  // view controller of second tab
}
@property (nonatomic, retain) IBOutlet UITabBar *mainTabBar;
@property (nonatomic, retain) UIViewController *tab1vc;
@property (nonatomic, retain) UIViewController *tab2vc;
@property (nonatomic, retain) UIViewController *tab3vc;
@property (nonatomic, retain) UIViewController *tab4vc;

@end

HomeViewController.m

HomeViewController.m

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
// item is the selected tab bar item
switch (item.tag) {
    case 1:
        if (tab1vc == nil) {
            self.tab1vc =[[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];

        }
        [self.view insertSubview:tab1vc.view belowSubview:mainTabBar];
         self.title = @"Home";
        label.text = self.title;
        //[tab1vc release];
        NSLog(@"1st");

        break;
    case 2:
        if (tab2vc == nil) {
            self.tab2vc =[[Tab2 alloc] initWithNibName:@"Tab2" bundle:nil];

        }
        [self.view insertSubview:tab2vc.view belowSubview:mainTabBar];
        //[tab2vc release];

        self.title = @"Tab2";
        label.text = self.title;
         NSLog(@"2st");


        break;
    case 3:
        if (tab3vc == nil) {
            self.tab3vc =[[Tab3 alloc] initWithNibName:@"Tab3" bundle:nil];

        }
        [self.view insertSubview:tab3vc.view belowSubview:mainTabBar];
        //[tab2vc release];

        self.title = @"Tab3";
        label.text = self.title;
        NSLog(@"3rd");
        break;

    case 4:
        if (tab4vc == nil) {
            self.tab4vc =[[Tab4 alloc] initWithNibName:@"Tab4" bundle:nil];

        }
        [self.view insertSubview:tab4vc.view belowSubview:mainTabBar];
        //[tab2vc release];

        self.title = @"Tab4";
        label.text = self.title;
        NSLog(@"4th");
        break;

    default:
        break;
}

}

现在它运作良好

这篇关于如何使用ios中的选项卡制作滑动菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆