Processing a view controller that slides in any direction

I am creating an application for iOS6 +. The application will have a primary view controller at one point in the application.

I would like this main view controller to process swipe to the left and scroll right on the screen to then display another view controller.

Is there an easy way to do this in the iOS6 + kernel, or should I look for another library, etc.

I already use a menu-style slide where in the application. I also understand and can find a million alternatives to these.

I am looking to have one View Controller (which acts in the middle). Then, when they scroll left / right, another controller is displayed. Then they can reverse the movement in the opposite direction or press the "Back" button to return to the main controller.

Edit-
In particular, I am looking for the following functions: Preload the controller that will slide. When a swipe happens (happens) ... the controller drags / pulls in with a touch. The same drag / scroll occurs anyway when the controller scrolls (left / right).

EDIT 2 -
I am looking for the functionality of dragging a view controller with my finger. Depending on how the drag and drop occurs, it will pull the same view controller.

I. The layout will be: [VC for Drag] [Main controller] [VC for Drag].
If the user iterates from left to right or from right to left, the other controller is dragged from the top, and they can return to the main controller using the opposite scroll.

+6
source share
5 answers

My favorite sidebar controller: https://github.com/mutualmobile/MMDrawerController

MMDrawerController is very customizable and does everything you mentioned:

  • left and right controller support
  • preset side controllers
  • gesture drag and drop

If you are using a storyboard, you can use this extension to support the storyboard: https://github.com/TomSwift/MMDrawerController-Storyboard

EDIT:

Another option would be to use a UIPageViewController with a UIPageViewControllerTransitionStyleScroll transition UIPageViewControllerTransitionStyleScroll : https://developer.apple.com/library/ios/documentation/uikit/reference/UIPageViewControllerClassReferenceClassRef/UIPageViewControllerClassReference.html

This will lead to the “pulling” behavior in the controllers on the side and “expanding” them.

EDIT 2: example for request

The only real complicating requirement you have is that the same view controller is used for both the left and the right. This means that we must keep track of where the view controller is presented so that we can properly manage our data source. Without this requirement, we could simply return our data source with an array and get the next / previous of this.

First of all, storyboard. There are three view controllers in the storyboard: 1) UIPageViewController , which I have classified as TSPageViewController . Remember to set the transition style property on the scroll page of the controller. 2) a center controller; and 3) a side controller. For center and side, I set the storyboard identifier of each of them to “center” and “side”, respectively. For this sample, both the central and side controllers have simple vanilla UIViewControllers , and I set their backgroundColor view to tell them apart.

enter image description here

Secondly, the pageview controller:

.h

 @interface TSPageViewController : UIPageViewController @end 

.m

 @interface TSPageViewController () <UIPageViewControllerDataSource> @end @implementation TSPageViewController { UIViewController* _side; UIViewController* _center; } - (void) viewDidLoad { [super viewDidLoad]; self.dataSource = self; _side = [self.storyboard instantiateViewControllerWithIdentifier: @"side"]; _center = [self.storyboard instantiateViewControllerWithIdentifier: @"center"]; [self setViewControllers: @[_center] direction: UIPageViewControllerNavigationDirectionForward animated: NO completion: nil]; } - (UIViewController*) pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController { if ( viewController == _center ) { _side.title = @"right"; return _side; } if ( viewController == _side && [_side.title isEqualToString: @"left"] ) { return _center; } return nil; } - (UIViewController*) pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController { if ( viewController == _center ) { _side.title = @"left"; return _side; } if ( viewController == _side && [_side.title isEqualToString: @"right"] ) { return _center; } return nil; } @end 

Again, the only thing that is especially important is to keep track of whether the side controller is currently “left” or “right.” This implementation has a problem in that it relies on the behavior of the UIPageViewController, rather than on the "page forward" and on the cache controllers (if this happened, our logic would be confused). Therefore, you can think of a more reliable mechanism for tracking the side on which the view controller is currently turned on. To do this, you will most likely have to enter your own gesture recognizer and use the data to track left / right movement.

If you can give up your requirement to use the same view controller for left and right, then you can have separate left / right / center controllers stored in the array and return next / prev controllers based on what you see in the array. Much easier and more reliable!

+6
source

for iOS6 +:

I would be inclined to use https://github.com/pkluz/PKRevealController and just set both left and right viewControllers for pointers to one viewController.


for iOS7 +:

I think you should look for custom UIViewController transitions.

https://github.com/ColinEberhardt/VCTransitionsLibrary

http://www.teehanlax.com/blog/custom-uiviewcontroller-transitions/

There is a good WWDC 2013 video on this subject entitled "Custom Transitions Using View Controllers", this is session 218.

+2
source

You can accomplish this with some cocoa controls, such as:

https://github.com/Inferis/ViewDeck

https://github.com/gotosleep/JASidePanels

EDIT: sentence number two, use a scrollView list controller:

 // 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 above code is written by heart, I probably incorrectly named a few things, and there is more than one way to handle the spy. The specified pageViewController in the comments will also work.

0
source

Sounds like work for a UISwipeGestureRecognizer .

-1
source

What you are looking for is very similar to the Apple iPhone version of UIPageControl Demo ;

-1
source

Source: https://habr.com/ru/post/955841/


All Articles