在没有导航菜单的情况下使用ECSliding切换视图 [英] Switching views with ECSliding without navigation menu
问题描述
我正在使用 ECSlidingViewController .
I'm using ECSlidingViewController.
在示例项目中,我在带有IBAction的第一"视图上添加了一个按钮
我希望第一个视图上的按钮转到第二个视图(不使用滑出导航).
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
推荐答案
不要总是使用self.slidingViewController
.这是一个派生属性,而不是静态值.因此,发生的事情是用第二个视图替换了第一个视图,然后第一个视图再也无法获得滑动控制器(破坏了它的引用).因此,改为这样做:
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];
}];
}
这篇关于在没有导航菜单的情况下使用ECSliding切换视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!