大家好,我已经搞砸了几种不同的方法来实现这个但似乎无法使任何工作。我要做的是拥有一个标准的UIPageView控制器,顶部有一个工具栏,然后当左上方的工具栏按钮向右移动PageView幻灯片时(例如Path或Facebook),显示一个tableView。 / p>
我能够让任何一个单独工作没问题,但我很难让这些多个视图控制器与appDelegate一起工作。我主要使用ViewDeck:https://github.com/Inferis/ViewDeck进行幻灯片实现,但如果还有另一种方法可以更方便地使用pageviewcontroller实现,我肯定会对它开放。
我发布的代码并不多,因为我仍然只是试图从概念上解决这个问题。
感谢您的帮助!
答案 0 :(得分:0)
编辑后:
要做你想做的事情,我认为最好将下一个控制器添加为页面视图控制器的子视图控制器(这是DataViewController中的self.parentViewController)。
#import "DataViewController.h"
#import "NextController.h"
#import "ModelController.h"
@implementation DataViewController {
BOOL viewRevealed;
NextController *next;
}
- (void)viewDidLoad {
[super viewDidLoad];
viewRevealed = NO;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.dataLabel.text = [self.dataObject description];
}
-(IBAction)slideInController:(UIButton *) sender {
if (viewRevealed == NO) {
next = [self.storyboard instantiateViewControllerWithIdentifier:@"Blue"];
next.view.frame = self.parentViewController.view.frame;
[self.parentViewController addChildViewController:next];
[self.parentViewController.view insertSubview:next.view belowSubview:self.view];
[next didMoveToParentViewController:self.parentViewController];
[UIView animateWithDuration:.6 animations:^{
self.view.frame = CGRectMake(self.view.frame.origin.x + self.view.frame.size.width/2, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
} completion:^(BOOL finished) {
viewRevealed = YES;
[(ModelController *)[(UIPageViewController *)self.parentViewController dataSource] setSlidOff:TRUE];
}];
}else{
[UIView animateWithDuration:.6 animations:^{
self.view.frame = CGRectMake(self.view.frame.origin.x - self.view.frame.size.width/2 , self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
} completion:^(BOOL finished) {
[next.view removeFromSuperview];
[next removeFromParentViewController];
viewRevealed = NO;
[(ModelController *)[(UIPageViewController *)self.parentViewController dataSource] setSlidOff:FALSE];
}];
}
}
这是DataViewController中的所有代码。我添加了几个必要的ivars。在我的测试应用程序中,我将slideInController方法连接到双击手势识别器。如果在DataView部分在屏幕上时单击或滑动,会发生奇怪的事情,因此我在ModelController.h文件(slidOff)中添加了BOOL属性,并在该类的init方法中将其设置为FALSE。然后我在两个页面视图数据源方法中的if语句中添加了另一个条件来检查该属性。当slidOff为TRUE时,滑动手势识别器不会做任何事情。以下是ModelController中的两个方法,因为我修改了它们:
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = [self indexOfViewController:(DataViewController *)viewController];
if ((index == 0) || (index == NSNotFound) || _slidOff) {
return nil;
}
index--;
return [self viewControllerAtIndex:index storyboard:viewController.storyboard];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = [self indexOfViewController:(DataViewController *)viewController];
if (index == NSNotFound || _slidOff) {
return nil;
}
index++;
if (index == [self.pageData count]) {
return nil;
}
return [self viewControllerAtIndex:index storyboard:viewController.storyboard];
}