我有两个按钮,可以用来启动UIPageViewController中的页面转换。我以如下的编程方式开始从一个页面到另一个页面的转换:
//to go left
[_pageVC setViewControllers:@[[self pageViewController:_pageVC viewControllerBeforeViewController:[_pageVC.viewControllers lastObject]]]
direction:UIPageViewControllerNavigationDirectionReverse
animated:YES
completion:^(BOOL finished) { }];问题是按钮的位置使得点击它们几次非常容易,这会导致不想要的行为,甚至导致应用程序崩溃。所以我想在页面转换的时候关闭它们。
为此,我创建了一个BOOL,在动画启动时将其设置为YES,但我不知道在哪里再次将其设置为NO。上面函数中的完成块被过早调用,如果转换是通过编程方式启动的(从docs:Called after a gesture-driven transition completes),则不会调用pageViewController:didFinishAnimating:previousViewControllers:transitionCompleted:。
如何在执行转换时禁用按钮?
发布于 2014-11-17 09:07:02
我使用了来自pbasdf的解决方案来禁用按钮,但它可能已经正常工作了。我意识到问题不在于按钮的失效,而是因为滑动仍然很活跃,导致了奇怪的行为。
当使用this method启用/禁用按钮时,我禁用并启用了滑动。
-(void)setPVScrollEnabled:(BOOL)scrollEnabled
{
for (UIScrollView *view in self.pageViewController.view.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
view.scrollEnabled = scrollEnabled;
}
}
}发布于 2014-11-17 10:05:31
加个暂停。例如,禁用按钮0.5秒:
self.buttonNext.enabled = NO;
self.buttonPrev.enabled = NO;
[_pageVC setViewControllers:@[[self pageViewController:_pageVC viewControllerBeforeViewController:[_pageVC.viewControllers lastObject]]]
direction:UIPageViewControllerNavigationDirectionReverse
animated:YES
completion:nil];
__weak YourClass *weakSelf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
weakSelf.buttonNext.enabled = YES;
weakSelf.buttonPrev.enabled = YES;
});https://stackoverflow.com/questions/26912447
复制相似问题