Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 自定义呈现的UICollectionView&x27的UINavigationController故障;转换期间的内容偏移量_Ios_Swift_Uinavigationcontroller_Uikit_Custom Transition - Fatal编程技术网

Ios 自定义呈现的UICollectionView&x27的UINavigationController故障;转换期间的内容偏移量

Ios 自定义呈现的UICollectionView&x27的UINavigationController故障;转换期间的内容偏移量,ios,swift,uinavigationcontroller,uikit,custom-transition,Ios,Swift,Uinavigationcontroller,Uikit,Custom Transition,我今天发现了一只奇怪的虫子。这是一张gif。 为了更好的测量,一张清晰地显示它的图像。 如您所见,topViewController中的UICollectionView在推到下一个视图控制器之前会出现奇怪的起伏偏移行为 我怀疑问题可能在于UINavigationController的自定义表示,它表示我从中推出的水平卡 下面是如何进行的自定义代码。出现故障的视图控制器只是一个普通的navigationController?.pushViewController(viewController,

我今天发现了一只奇怪的虫子。这是一张gif。

为了更好的测量,一张清晰地显示它的图像。

如您所见,
topViewController
中的
UICollectionView
在推到下一个视图控制器之前会出现奇怪的起伏偏移行为

我怀疑问题可能在于
UINavigationController
的自定义表示,它表示我从中推出的水平卡

下面是如何进行的自定义代码。出现故障的视图控制器只是一个普通的
navigationController?.pushViewController(viewController,动画:true)
从俯视图控制器推送

片段A-演示文稿

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    guard let viewModel = viewModel else { return }
    // V This is a UINavigationController
    let viewController = viewModel.getViewController(displayingOfferAt: indexPath.item)
    viewController.modalPresentationStyle = .custom
    viewController.transitioningDelegate = self
    present(viewController, animated: true)
}
片段B-正在转换的委托

extension StorefrontViewController: UIViewControllerTransitioningDelegate {
    func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
        switch presented {
        case is CashStore.FullNavigationController:
            return CashStore.FullPresentationController(presentedViewController: presented, presenting: presenting)
        default:
            return nil
        }
    }
}
片段C-演示控制器

class FullPresentationController: UIPresentationController {

    // MARK: Outlets

    private lazy var backgroundView: UIView = {
        $0.isUserInteractionEnabled = true
        $0.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.8016641695)

        return $0
    }(UIView())


    // MARK: Overrides

    override func containerViewDidLayoutSubviews() {
        super.containerViewDidLayoutSubviews()

        presentedView?.frame = frameOfPresentedViewInContainerView
        backgroundView.frame = containerView!.bounds
    }

    override func presentationTransitionWillBegin() {
        backgroundView.alpha = 0.0
        containerView?.addSubview(backgroundView)
        presentedViewController.transitionCoordinator?.animate(alongsideTransition: { context in
            self.backgroundView.alpha = 1.0
        })
    }

    override func dismissalTransitionWillBegin() {
        presentedViewController.transitionCoordinator?.animate(alongsideTransition: { context in
            self.backgroundView.alpha = 0.0
        }, completion: { context in
            self.backgroundView.removeFromSuperview()
        })
    }


    // MARK: Actions

    @objc func dismiss() {
        presentingViewController.dismiss(animated: true)
    }
}
class FullNavigationController: TiseNavigationController {
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .clear
    }
}
片段D-用于捕捉的自定义集合视图布局

class ProductFlowLayout: UICollectionViewFlowLayout {

    override init() {
        super.init()
        scrollDirection = .horizontal
    }

    required init?(coder _: NSCoder) {
        return nil
    }

    override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint {
        guard let collectionView = collectionView else {
            return super.targetContentOffset(forProposedContentOffset: proposedContentOffset, withScrollingVelocity: velocity)
        }

        var offsetAdjustment = CGFloat.greatestFiniteMagnitude
        let horizontalOffset = proposedContentOffset.x + collectionView.contentInset.left

        let targetRect = CGRect(x: proposedContentOffset.x, y: 0, width: collectionView.bounds.size.width, height: collectionView.bounds.size.height)

        let layoutAttributesArray = super.layoutAttributesForElements(in: targetRect) ?? []

        for attributes in layoutAttributesArray where fabsf(Float(attributes.frame.origin.x - horizontalOffset)) < fabsf(Float(offsetAdjustment)) {
            offsetAdjustment = attributes.frame.origin.x - horizontalOffset
        }

        let flowDelegate = collectionView.delegate as? UICollectionViewDelegateFlowLayout
        let leftInset = flowDelegate?.collectionView?(collectionView, layout: self, insetForSectionAt: 0).left ?? 0.0
        let targetOffset = CGPoint(x: proposedContentOffset.x + offsetAdjustment - leftInset, y: proposedContentOffset.y)

        return targetOffset
    }
}
类ProductFlowLayout:UICollectionViewFlowLayout{
重写init(){
super.init()
滚动方向=水平方向
}
必需的初始化?(编码器:NSCoder){
归零
}
覆盖func targetContentOffset(forProposedContentOffset proposedContentOffset:CGPoint,使用CrollingVelocity:CGPoint)->CGPoint{
guard let collectionView=collectionView else{
返回super.targetContentOffset(forProposedContentOffset:proposedContentOffset,带CrollingVelocity:velocity)
}
var offsetAdjustment=CGFloat.greatestFiniteMagnitude
设horizontalOffset=proposedContentOffset.x+collectionView.contentInset.left
设targetRect=CGRect(x:proposedContentOffset.x,y:0,宽度:collectionView.bounds.size.width,高度:collectionView.bounds.size.height)
让layoutAttributesArray=super.layoutAttributesForElements(在:targetRect中)??[]
对于布局属性阵列中的属性,其中fabsf(Float(attributes.frame.origin.x-horizontalpoffset))

我已尝试禁用内容偏移调整,但没有改变任何内容。我还尝试在带有卡的视图控制器和集合视图上禁用
maskToBounds
,但没有成功。对不起,问题太长了,我希望有人能帮我解决这个奇怪的问题