[英]The view is “jumping” when I add it to UIWindow as subview (via rootViewController property) and do a flip
[英]Should I add bottom sheet as a subview to current view controller or push a UIWindow with the subView added?
您不應該創建一個新的UIWindow
。 通常,一個iOS應用只有1個窗口。 我看到的兩個最佳選擇是:
您可以添加子視圖和手勢識別器以實現拉動。 這意味着所有邏輯都可能在父UIViewController
。 如果沒有太多邏輯,並且不必重新使用工作表,則這是一個不錯的選擇。
如果工作表內部有更多邏輯,或者工作表具有可重用性,則最好為此創建一個單獨的UIViewController
。 然后,您可以使用自定義動畫和演示控制器來演示此內容。 UIPresentationController
,請查看UIViewControllerAnimatedTransitioning
和UIPresentationController
。
我之前使用過第二個選項。 UIPresentationController
負責將工作表視圖放置在屏幕底部。 它還可以使背景變暗,並附加手勢識別器以處理拉動和拉開。
您可以使用本教程開始使用UIPresentationController
。 您還可以從此處獲取代碼,並使其適應您的需求: https : //www.raywenderlich.com/915-uipresentationcontroller-tutorial-getting-started
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.