久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用(自定義、交互式)視圖控制器呈現和解除處理

Handling scroll views with (custom, interactive) view controller presentation and dismissal(使用(自定義、交互式)視圖控制器呈現和解除處理滾動視圖)
本文介紹了使用(自定義、交互式)視圖控制器呈現和解除處理滾動視圖的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我一直在嘗試自定義交互式視圖控制器的展示和解除(使用 UIPresentationControllerUIPercentDrivenInteractiveTransitionUIViewControllerAnimatedTransitioning 的組合>UIViewControllerTransitioningDelegate) 并且大多數情況下都可以很好地滿足我的需求.

但是,在我閱讀的任何教程或文檔中,我還沒有找到一種常見的情況,這導致我提出以下問題:

...

當被解除的視圖包含 UIScrollView(即 UITableView、UICollectionView、WKWebView 等)時,通過平移手勢處理自定義交互式視圖控制器解除的正確方法是什么?

...

基本上,我想要的是以下內容:

  1. 視圖控制器可以通過向下平移以交互方式關閉.這是許多應用程序中常見的用戶體驗.

  2. 如果關閉的視圖控制器包含(垂直滾動)滾動視圖,則向下平移會按預期滾動該視圖,直到用戶到達頂部,然后滾動停止并發生平移關閉.

  3. 滾動視圖應該正常運行.

我知道這在技術上是可能的 - 我在其他應用程序中看到過它,例如 Overcast 和 Apple 自己的音樂應用程序 - 但我無法找到協調我的平移手勢的行為與滾動視圖的行為.

我自己的大部分嘗試都集中在嘗試在滾動時根據其 contentOffset.y 有條件地啟用/禁用滾動視圖(或其關聯的平移手勢識別器)并讓視圖控制器解除的平移手勢識別器從那里接管,但這充滿了問題,我擔心我想多了.

我覺得秘密主要在于以下平移手勢識別器委托方法:

funcgestureRecognizer(_gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) ->布爾 {//...}

我創建了一個簡化的示例項目,它應該更清楚地展示場景.非常歡迎任何代碼建議!

I have been experimenting with custom interactive view controller presentation and dismissal (using a combination of UIPresentationController, UIPercentDrivenInteractiveTransition, UIViewControllerAnimatedTransitioning, and UIViewControllerTransitioningDelegate) and have mostly gotten things working well for my needs.

However, there is one common scenario that I've yet to find addressed in any of the tutorials or documentation that I've read, leading me to the following question:

...

What is the proper way of handling custom interactive view controller dismissal, via a pan gesture, when the dismissed view contains a UIScrollView (ie. UITableView, UICollectionView, WKWebView, etc)?

...

Basically, what I'd like is for the following:

  1. View controllers are interactively dismissible by panning them down. This is common UX in many apps.

  2. If the dismissed view controller contains a (vertically-scrolling) scroll view, panning down scrolls that view as expected until the user reaches the top, after which the scrolling ceases and the pan-to-dismiss occurs.

  3. Scroll views should otherwise behave as normal.

I know that this is technically possible - I've seen it in other apps, such as Overcast and Apple's own Music app - but I've not been able to find the key to coordinating the behavior of my pan gesture with that of the scroll view(s).

Most of my own attempts center on trying to conditionally enable/disable the scrollview (or its associated pan gesture recognizer) based on its contentOffset.y while scrolling and having the view controller dismissal's pan gesture recognizer take over from there, but this has been fraught with problems and I fear that I am overthinking it.

I feel like the secret mostly lies in the following pan gesture recognizer delegate method:

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
   // ...
}

I have created a reduced sample project which should demonstrate the scenario more clearly. Any code suggestions are highly welcome!

https://github.com/Darchmare/SlidePanel-iOS

解決方案

Solution

  • Make scrollView stop scrolling after it reached top by using UIScrollView's bounces property and scrollViewDidScroll(_:) method.

    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        scrollView.bounces = (scrollView.contentOffset.y > 10);
    }
    

    Don't forget to set scrollView.delegate = self

  • Only handle panGestureRecognizer when scrollView reached top - It means when scrollView.contentOffset.y == 0 by using a protocol.

    protocol PanelAnimationControllerDelegate {
        func shouldHandlePanelInteractionGesture() -> Bool
    }
    

    ViewController

    func shouldHandlePanelInteractionGesture() -> Bool {
        return (scrollView.contentOffset.y == 0);
    }
    

    PanelInteractionController

    class PanelInteractionController: ... {
    
      var startY:CGFloat = 0
    
      private weak var viewController: (UIViewController & PanelAnimationControllerDelegate)?
    
      @objc func handlePanGestureRecognizer(_ gestureRecognizer: UIPanGestureRecognizer) {
        switch gestureRecognizer.state {
        case .began:
          break
        case .changed:
          let translation    = gestureRecognizer.translation(in: gestureRecognizer.view!.superview!)
          let velocity    = gestureRecognizer.velocity(in: gestureRecognizer.view!.superview)
          let state      = gestureRecognizer.state
    
          // Don't do anything when |scrollView| is scrolling
          if !(viewController?.shouldHandlePanelInteractionGesture())! && percentComplete == 0 {
            return;
          }
    
          var rawProgress    = CGFloat(0.0)
    
          rawProgress    = ((translation.y - startTransitionY) / gestureRecognizer.view!.bounds.size.height)
    
          let progress    = CGFloat(fminf(fmaxf(Float(rawProgress), 0.0), 1.0))
    
          if abs(velocity.x) > abs(velocity.y) && state == .began {
            // If the user attempts a pan and it looks like it's going to be mostly horizontal, bail - we don't want it... - JAC
            return
          }
    
          if !self.interactionInProgress {
            // Start to pan |viewController| down
            self.interactionInProgress = true
            startTransitionY = translation.y;
            self.viewController?.dismiss(animated: true, completion: nil)
          } else {
            // If the user gets to a certain point within the dismissal and releases the panel, allow the dismissal to complete... - JAC
            self.shouldCompleteTransition = progress > 0.2
    
            update(progress)
          }
        case .cancelled:
          self.interactionInProgress = false
          startTransitionY = 0
    
          cancel()
        case .ended:
          self.interactionInProgress = false
          startTransitionY = 0
    
          if self.shouldCompleteTransition == false {
            cancel()
          } else {
            finish()
          }
        case .failed:
          self.interactionInProgress = false
          startTransitionY = 0
    
          cancel()
        default:
          break;
        }
      }
    }
    

Result

For more detail, you can take a look at my sample project

這篇關于使用(自定義、交互式)視圖控制器呈現和解除處理滾動視圖的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView(scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的邊緣工作) - IT屋-程序員軟件開發技術分享社
ImageView Scaling when scrolling down(向下滾動時 ImageView 縮放)
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的邊界自動更改,帶有內容插圖)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干擾按鈕.怎么修?)
Dynamic height TableView in a Scroll View(滾動視圖中的動態高度 TableView)
主站蜘蛛池模板: 国产精品无码专区在线观看 | 成av在线| 一区二区三区在线 | 中文一区二区 | 91视视频在线观看入口直接观看 | 亚洲码欧美码一区二区三区 | 亚洲免费人成在线视频观看 | 精产国产伦理一二三区 | 久久久久久综合 | 宅女噜噜66国产精品观看免费 | 国产婷婷在线视频 | 伊人在线 | 日韩伦理一区二区 | 久久99精品久久久久久秒播九色 | 狠狠干综合视频 | 欧美日韩国产在线 | 日本不卡免费新一二三区 | 色姑娘综合网 | 国产精品福利视频 | 黄色网一级片 | 视频一区二区国产 | 伦理午夜电影免费观看 | 日韩爱爱网站 | www.精品国产 | 波多野结衣一区二区三区 | 久久精品亚洲成在人线av网址 | 久久99精品久久久 | 国产午夜精品一区二区三区四区 | 国产成人免费 | 91av视频在线播放 | 亚洲天堂男人的天堂 | 午夜一级大片 | 成人h视频在线 | 亚洲综合久久精品 | 国产一区二区精品在线观看 | 91p在线观看 | 911精品美国片911久久久 | 国产一区二区三区免费观看在线 | 午夜一级黄色片 | 亚洲国产精品一区二区久久 | 欧美精品一区二区三区在线播放 |