【问题标题】:SlideView starting below the navigationBar in PPRevealSlideViewController从 PPRevealSlide ViewController 中导航栏下方开始的幻灯片视图
【发布时间】:2013-09-25 13:26:46
【问题描述】:

在我的应用程序中,我正在使用 PPRevealSlideViewController。

问题是右侧视图出现在导航栏下方,如图中红色椭圆所示。它不是从极端顶部开始的。解决方法是什么?

左右侧viewControllers都有navigationBar。

代码:

MainController main = [[MainController alloc] initWithNibName:@"MainController" bundle:nil];

UINavigationController *navMainController = [[UINavigationController alloc] initWithRootViewController:main];

PPRevealSideViewController *revealSideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:navMainController];

revealSideViewController.delegate = main;

[self.navController pushViewController:revealSideViewController animated:YES];

[main release];

【问题讨论】:

    标签: ios uinavigationcontroller


    【解决方案1】:

    你需要在你的项目中隐含 PPRevealSlideViewController 像这样:-

    LoginPageViewController *login = [[LoginPageViewController alloc]initWithNibName:@"LoginPageView" bundle:nil];  
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:login];
    _revealSideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:nav];
    [self.window setRootViewController:_revealSideViewController];
    

    我认为在你的代码中你添加了两个导航控制器你只需要添加一个导航控制器而你将PPRevealSideViewController添加到主pushviewcontroller到self.window

    例如,您可以做到这一点

    在你HomeViewcontroller push rightViewcontroller你需要再次将Viewcontrollre作为rootviewcontroller添加#import <QuartzCore/QuartzCore.h>:-

    ObjAppDelegate=(AppDelegate*)[[UIApplication sharedApplication]delegate]; //创建appdelegate对象

    -(IBAction)ActionPushrightViewcontroller
    {
    
             rightViewcontroller *login = [[rightViewcontroller alloc]initWithNibName:@"rightViewcontroller" bundle:nil];  
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:login];
        _revealSideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:nav];
    
              [ObjAppDelegate.window setRootViewController:_revealSideViewController];
                 UIInterfaceOrientation interfaceOrientation = _revealSideViewController.interfaceOrientation;
            NSString *subtypeDirection;
            if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
                subtypeDirection = kCATransitionFromTop;
            }
            else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
                subtypeDirection = kCATransitionFromBottom;
            }
            else {
                subtypeDirection = kCATransitionFromRight;
            }
            [ObjAppDelegate.window setRootViewController:_revealSideViewController];
            CATransition *animation = [CATransition animation];
            [animation setDuration:0.5];
            [animation setType:kCATransitionPush];
            [animation setSubtype:subtypeDirection];
            [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    
            [[ObjAppDelegate.window layer] addAnimation:animation forKey:@"SwitchToView1"];
    
    
    }
    

    如果你想支持你的 Home 视图控制器,请使用以下代码:-

    -(IBAction)ActionPopHomeviewcontroller
    {
    
             Homeviewcontroller *Home = [[Homeviewcontroller alloc]initWithNibName:@"Homeviewcontroller" bundle:nil];  
             UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:Home];
    
                UIInterfaceOrientation interfaceOrientation = viewController.interfaceOrientation;
                NSString *subtypeDirection;
                if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
                    subtypeDirection = kCATransitionFromTop;
                }
                else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
                    subtypeDirection = kCATransitionFromBottom;
                }
                else {
                    subtypeDirection = kCATransitionFromLeft;
                }
    
                [ObjAppDelegate.window setRootViewController:nav];
    
    
                CATransition *animation = [CATransition animation];
                [animation setDuration:0.5];
                [animation setType:kCATransitionPush];
                [animation setSubtype:subtypeDirection];
                [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    
                [[ObjAppDelegate.window layer] addAnimation:animation forKey:@"SwitchToView1"];
    
    
    }
    

    【讨论】:

    • @parilogic 是您在尝试添加 PPRevealSideViewController 时添加了两个导航控件,其中一个已进入 rightviewcontroller
    • mainviewcontroller 也是从 appdelegate 添加到导航控制器的吧?
    • 当我编写代码时,只需创建一个 appdelegate 的 Obj 并使用委托对象获取它的窗口类,并使用 CATransition 推送弹出动画再次将主视图控制器添加为根视图控制器
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    • 2015-05-12
    相关资源
    最近更新 更多