Reputation: 3862
Inside a collectionViewCell
I want to create a view with dots on the bottom and where I can swipe between the views. Shall I use UIPageController
to show the dots and implement the gesture recognition manually or is it possible to use UIPageViewController
inside the collectionViewCell
?
Upvotes: 1
Views: 1217
Reputation: 261
In swift:
let pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
pageViewController.view.frame = view.frame//set frame
self.addChildViewController(pageViewController)
view.addSubview(pageViewController.view)
pageViewController.didMove(toParentViewController: self)
Upvotes: 1
Reputation: 2099
Yes you can have it in your cell. It doesn't have to be full screen. In fact it can be used as any other UIViewController. If you want to embed it in a smaller rectangle, you can use UIViewController containment.
Let's assume that you want to embed it into a parent controller which is a UIViewController subclass. Then define a pageViewController property and add it as a child view controller in viewDidLoad:
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.view.frame = ... //set the frame or add autolayout constraints
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
Upvotes: 1