微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用自定义 segue 时出现 Swift 约束问题

如何解决使用自定义 segue 时出现 Swift 约束问题

我正在使用自定义 segue 来呈现视图控制器,当我不使用任何约束时它工作正常,一旦我向目标视图控制器上的标签添加约束,它就会弹出一个错误说:>

“流布局不支持负尺寸”

Segue

这是我的自定义转场代码

class PresentTimeMachinesegue: UIStoryboardSegue {
    
    override func perform() {
        destination.transitioningDelegate = self
        destination.modalPresentationStyle = .fullScreen
        source.present(destination,animated: true,completion: nil)
    }
}

extension PresentTimeMachinesegue: UIViewControllerTransitioningDelegate {
    public func animationController(forPresented presented: UIViewController,presenting: UIViewController,source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return TimeMachineViewPresentAnimationController()
    }
        
    public func animationController(fordismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        return TimeMachineViewPresentAnimationController()
    }
}

class TimeMachineViewPresentAnimationController: NSObject,UIViewControllerAnimatedTransitioning {
    
   
    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        return 0.5
    }
    
    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
CalendarViewController
        let containerView = transitionContext.containerView
        let toViewController = transitionContext.viewController(forKey: .to) as! TimeMachineViewController
        

        print("transition")
        if toViewController.calendarView != nil {

            //toViewController.view.addSubview(toViewController.calendarView!)
            containerView.addSubview(toViewController.view)
            toViewController.inlitializeUI()
        }
        
        toViewController.view.backgroundColor = UIColor.white.withAlphaComponent(0)
        
        UIView.animate(withDuration: 0.8,animations: {
            toViewController.view.backgroundColor = UIColor.white.withAlphaComponent(1)
        }) { _ in
            
            transitionContext.completeTransition(true)
 
        }
        
        
    }
    
    
}

Error

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。