I got a viewController
which inherits from UIPageViewController
( @interface PageScrollViewController : UIPageViewController
) Now I'm wondering how I can enable and disable the scrolling from the UIPageViewController
? When using a UIScrollView
you would do setScrollEnabled:NO
and self.view.userInteractionEnabled = NO;
isn't an option since this blocks the whole UIView
instead of just the scrolling.
EDIT
This is in the PageScrollViewController : UIPageViewController
class:
if ([[notification name] isEqualToString:@"NotificationDisable"]){
NSLog (@"Successfully received the disable notification!");
for (UIGestureRecognizer *recognizer in self.gestureRecognizers) {
recognizer.enabled = NO;
}
}
UIPageViewController
manages a UIScrollView
internally to get things done. We can find out that UIScrollView
and update its isScrollEnabled
property.
let view = myPageViewController.view
for subview in view.subviews {
if let scrollview = subview as? UIScrollView {
scrollview.isScrollEnabled = false
break
}
}
Or use this UIPageViewController
extension.
extension UIPageViewController {
var scrollView: UIScrollView {
for subview in view.subviews {
if let scrollview = subview as? UIScrollView {
return scrollview
}
}
fatalError()
}
var isScrollEnabled: Bool {
get {
return scrollView.isScrollEnabled
}
set {
scrollView.isScrollEnabled = newValue
}
}
}
Or you can cast in your PagingVC To disable paging:
self.delegate = nil;
self.dataSource = nil;
And for enable it again:
self.delegate = self;
self.dataSource = self;
Try looping through the gestureRecognizers
of the UIPageViewController
and disable/enable them:
for (UIGestureRecognizer *recognizer in pageViewController.gestureRecognizers) {
recognizer.enabled = NO;
}
Note: as found in this SO post, this method will only work for UIPageViewControllerTransitionStylePageCurl
. You may want to try this solution (although it seems to be a bit hacky).
for recognizer in pageViewController.gestureRecognizers {
recognizer.isEnabled = false
}
I did the following thing (I have a controller that holds UIPageViewController).
self.pageController.view.userInteractionEnabled = NO;
And when you want to enable swipe or scroll, just enable user interaction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With