3D触控查看和弹出隐藏导航栏和状态栏

时间:2016-09-10 19:03:02

标签: ios swift uinavigationbar 3dtouch

启动视图控制器后,UINavigationBarUIStatusBar会在触摸视图之间暂时隐藏,并强制触摸以调出模态视图控制器。

以下是三种状态:

1。不点击

enter image description here

2。当您轻轻点击

enter image description here

第3。当您强行触摸时

enter image description here

为什么状态栏和导航栏会在第2步暂时消失,我该如何解决?

2 个答案:

答案 0 :(得分:0)

尝试

 navigationController?.hidesBarsOnSwipe = false

 navigationController?.hidesBarsOnTap = false

更新:

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

答案 1 :(得分:0)

在我的情况下,因为我没有在

中设置正确的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