【问题标题】:Using UIPageViewControllers scroll over entire view, including UIButtons使用 UIPageViewControllers 滚动整个视图,包括 UIButtons
【发布时间】:2015-03-18 05:16:36
【问题描述】:

我有一个带有 PageViewController 和 4 个 UIButtons 作为子视图的 UIView。 PageViewController 和按钮子视图是相互独立的。 (PageViewController 滚动 4 个页面,而 UIButtons 保持不变)

我面临的问题是按钮占用了相当多的空间,我想在 UIView 上的任何位置使用此滚动手势,包括带有按钮的区域。

如果用户点击按钮,则会发生相应的操作,但我希望我可以在按钮上开始滚动/滑动手势并让 PageViewControllers 滚动功能正常工作。

我已经尝试/搜索了几种方法,包括使用 UIScrollView 而不是 PageViewController。任何帮助将不胜感激。提前致谢。 :)

【问题讨论】:

  • 您尝试过添加手势吗?

标签: swift scroll uibutton swipe uipageviewcontroller


【解决方案1】:

只需添加您自己的手势识别器,并注意在 x 方向上速度较大且从左到右的手势。

    override func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {

        if (gestureRecognizer.isMemberOfClass(UIPanGestureRecognizer)){
            let point:CGPoint = (gestureRecognizer as UIPanGestureRecognizer).velocityInView(self)
            if (abs(point.x) > abs(point.y)){
                return true
            }
        }
}

在这里处理手势:

func handlePanGestureRecognizer(gesture: UIPanGestureRecognizer){
    let translation:CGPoint = gesture.translationInView(self)
    if(translation.x > 0){
       //its going from left to right...
       //...transition to the previous page
    }else{
       //...transition to the next page
}

【讨论】:

  • 非常感谢。我还没有尝试过(首先处理其他一些问题),但我认为它应该可以工作。 :)
猜你喜欢
  • 1970-01-01
  • 2015-07-22
  • 2020-10-28
  • 1970-01-01
  • 2012-06-23
  • 1970-01-01
  • 1970-01-01
  • 2021-10-28
  • 1970-01-01
相关资源
最近更新 更多