在视图控制器Xcode之间滚动

时间:2014-09-23 22:12:11

标签: ios objective-c xcode uiscrollview swipe

我正在尝试创建一个应用程序,其中有3个视图控制器,您可以使用滚动视图在它们之间滑动。

我设法让2个视图完美地工作但是当我尝试添加第三个视图时,它只是替换了第二个视图。

以下是代码:

    - (void)viewDidLoad
    {
    [super viewDidLoad];

    ChatsViewController *aViewController = [[ChatsViewController alloc]init];
    [self addChildViewController:aViewController];
    [self.scrollView addSubview:aViewController.view];
    [aViewController didMoveToParentViewController:self];

    FriendsViewController *bViewController = [[FriendsViewController alloc]init];
    CGRect frame = bViewController.view.frame;
    frame.origin.x = 320;
    bViewController.view.frame = frame;

    ProfileView *cViewController = [[ProfileView alloc]init];
    CGRect frame2 = cViewController.view.frame;
    frame2.origin.x = 640;
    cViewController.view.frame = frame;

    [self addChildViewController:bViewController];
    [self.scrollView addSubview:bViewController.view];
    [bViewController didMoveToParentViewController:self];

    [self addChildViewController:cViewController];
    [self.scrollView addSubview:cViewController.view];
    [cViewController didMoveToParentViewController:self];

    self.scrollView.contentSize = CGSizeMake(960, self.view.frame.size.height);
    self.scrollView.pagingEnabled = YES;

    }  

我正在使用此库:https://github.com/gneil90/CustomContainerViewController

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

你有

cViewController.view.frame = frame

应该是

cViewController.view.frame = frame2