簡體   English   中英

3D觸控查看和彈出隱藏導航欄和狀態欄

[英]3D touch peek and pop hides navigation bar and status bar

在啟動視圖控制器時, UINavigationBarUIStatusBar都會在觸摸視圖之間暫時隱藏並強制觸摸以調出模態視圖控制器。

以下是三種狀態:

1.沒有攻絲

在此輸入圖像描述

2.當你輕輕拍打時

在此輸入圖像描述

3.當你強行觸摸時

在此輸入圖像描述

為什么狀態欄和導航欄會在第2步暫時消失,我該如何解決?

嘗試

 navigationController?.hidesBarsOnSwipe = false

 navigationController?.hidesBarsOnTap = false

更新:

 override func prefersStatusBarHidden() -> Bool {
return false
 }

在我的情況下,因為我沒有設置正確的sourceRect

- (nullable UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext 
                       viewControllerForLocation:(CGPoint)location

iOS使用整個視圖框架作為sourceRect ,它與導航欄和狀態欄重疊。

例如,如果你在tableView或collectionView中使用它,你應該寫這樣的東西:

NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:location];
UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
// you need to check if indexPath or cell are nil
CGRect convertedRect = [cell convertRect:cell.bounds toView:self.collectionView];
previewingContext.sourceRect = convertedRect;
// and after that - return needed view controller

Swift版本:

guard let indexPath = collectionView.indexPathForItem(at: location),
      let cell = collectionView.cellForItem(at: indexPath) else {
    return nil
}
let convertedRect = cell.convert(cell.bounds, to: collectionView)
previewingContext.sourceRect = convertedRect
// and after that - return needed view controller

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM