禁用/启用UIPageViewController中的滚动 [英] Disable/enable scrolling in UIPageViewController
问题描述
我有一个 viewController
,它继承自 UIPageViewController
( @interface PageScrollViewController:UIPageViewController
)现在我想知道如何启用和禁用 UIPageViewController
中的滚动?使用 UIScrollView
时,你会做 setScrollEnabled:NO
和 self.view.userInteractionEnabled = NO ;
不是一个选项,因为这会阻止整个 UIView
,而不仅仅是滚动。
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.
编辑
这是在 PageScrollViewController:UIPageViewController
类:
if ([[notification name] isEqualToString:@"NotificationDisable"]){
NSLog (@"Successfully received the disable notification!");
for (UIGestureRecognizer *recognizer in self.gestureRecognizers) {
recognizer.enabled = NO;
}
}
推荐答案
尝试循环遍历 UIPageViewController
的 gestureRecognizers
并禁用/启用它们:
Try looping through the gestureRecognizers
of the UIPageViewController
and disable/enable them:
for (UIGestureRecognizer *recognizer in pageViewController.gestureRecognizers) {
recognizer.enabled = NO;
}
注意:在这个SO帖子,此方法仅适用于 UIPageViewControllerTransitionStylePageCurl
。你可能想尝试这个解决方案(虽然看起来有点像hacky)。
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).
这篇关于禁用/启用UIPageViewController中的滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!