Handling a view controller that slides in with either way swipe

前端 未结 5 1727
你的背包
你的背包 2021-02-06 11:27

I am building an application that is for iOS6+. The application will have a main View Controller at one point in the application.

I would like this main view controller

5条回答
  •  甜味超标
    2021-02-06 12:20

    You can accomplish that with some of the cocoa controls such as:

    https://github.com/Inferis/ViewDeck

    https://github.com/gotosleep/JASidePanels

    EDIT: Proposal number two, use a controller with a scrollView:

    // Allocate all the controlelrs you need
    MyFirstViewController *first = [[MyFirstViewController alloc] init];
    MySecondViewController *second= [[MySecondViewController alloc] init];
    MyThirdViewController *third = [[MyThirdViewController alloc] init];
    
    // Adjust the frames of the controllers
    first.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    second.view.frame = CGRectMake(0, self.view.frame.size.width, self.view.frame.size.width, self.view.frame.size.height);
    third .view.frame = CGRectMake(0, 2 * self.view.frame.size.width, self.view.frame.size.width, self.view.frame.size.height);
    
    // Add controllers as subViews to the scrollView
    [self.scrollView addSubview:self.first.view];
    [self.scrollView addSubview:self.second.view];
    [self.scrollView addSubview:self.third.view];
    
    // Set the scrollView contentSize and paging
    self.scrollView.contentSize = CGRectMake(self.view.frame.size.width * 3, self.view.frame.size.height);
    self.scrollView.pagingEnabled = YES;
    
    // Scroll to the middle view initally
    [self.scrollView scrollRectToVisible:CGRectMake(0, self.view.frame.size.width, self.view.frame.size.width, self.view.frame.size.height) animated:NO];
    

    The code above is written by heart, I have probably named a few things wrongly, and there is more than one way to handle the subviews. The mentioned pageViewController in the comments will work as well.

提交回复
热议问题