Switching views with ECSliding without navigation

2019-07-19 02:28发布

I'm using ECSlidingViewController.

In the sample project i added a button on the First view with an IBAction
I want the button on the First view to go to the second view (without using the slide out navigation).

- (IBAction)btnPressed:(id)sender {
    UIViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondTop"];
    [self.slidingViewController anchorTopViewOffScreenTo:ECRight animations:nil onComplete:^{
        CGRect frame = self.slidingViewController.topViewController.view.frame;
        self.slidingViewController.topViewController = newTopViewController;
        self.slidingViewController.topViewController.view.frame = frame;
        [self.slidingViewController resetTopView];
    }];
}

With this code it only goes to the navigation slide out menu and doesn't go to the Second

1条回答
冷血范
2楼-- · 2019-07-19 03:04

Don't always use self.slidingViewController. It's a derived property, not a static value. So what's happening is that you replace the first view with the second view and then the first view can't get the sliding controller any more (you broke its reference). So, do this instead:

- (IBAction)btnPressed:(id)sender {
    ECSlidingViewController *slidingViewController = self.slidingViewController;

    UIViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondTop"];
    [slidingViewController anchorTopViewOffScreenTo:ECRight animations:nil onComplete:^{
        CGRect frame = slidingViewController.topViewController.view.frame;
        slidingViewController.topViewController = newTopViewController;
        slidingViewController.topViewController.view.frame = frame;
        [slidingViewController resetTopView];
    }];
}
查看更多
登录 后发表回答