登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

自定义转场 present 设置了代理,为啥后面的视图还是消失了[复制链接]

[i=s] 本帖最后由 545792772 于 2019-1-29 18:20 编辑 [/i]

需求是这样的:收到后台的推送就弹窗,可以在app任何页面,弹窗可以点击,可能跳转到其他VC,返回后弹窗不消失。因为页面很多复用的地方,所以想用ViewController模拟弹窗。
遇到问题RT,视图present出来了,但是后面的vc没了,就是全黑。

Mac好像贴不了图,代码如下:
class LvTipViewManager: NSObject {


var isPresent = false

static let shareManager = LvTipViewManager()

var onShow = false

var tipVC: LvCustomTipVC?

func showNegotiateView() {
    if tipVC == nil {
        tipVC = LvCustomTipVC()
    }
    
    if onShow == false {
        let currentVC = UIApplication.getCurrentViewController()
        
        if currentVC == nil {
            return
        }
        currentVC?.transitioningDelegate = self
        currentVC?.modalPresentationStyle = .custom
        currentVC?.modalTransitionStyle = .partialCurl
        currentVC?.present(tipVC!, animated: true, completion: {
            self.onShow = true
        })
        
        tipVC?.showNegotiateUpdateView()
        tipVC?.contentViewDismissBlock = {[weak self] in
            self?.tipVC?.dismiss(animated: false, completion: {
                self?.onShow = false
            })
        }
    }
}

}

extension LvTipViewManager : UIViewControllerTransitioningDelegate {

func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
    return LvPresentationController(presentedViewController: presented, presenting: presenting)
}


func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    isPresent = true
    return self
}

func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    isPresent = false
    return self
}

}

extension LvTipViewManager : UIViewControllerAnimatedTransitioning {

func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
    return 0.5
}

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
    isPresent ? animateTransitionForPresent(transitionContext) : animateTransitionForDismiss(transitionContext)
}

// 弹出的动画
func animateTransitionForPresent(_ transitionContext: UIViewControllerContextTransitioning) {
    // 1、获取弹出的view
    let presentView = transitionContext.view(forKey: UITransitionContextViewKey.to)!
    // 2、将弹出的View添加到containerView上
    transitionContext.containerView.addSubview(presentView)
    // 3、执行动画
    presentView.transform = CGAffineTransform(scaleX: 1.0, y: 0.0)
    presentView.layer.anchorPoint = CGPoint.init(x: 0.5, y: 0) // 默认这个点在center,我们希望他在上面靠中间的位置
    UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: {
        // 动画执行完毕,还原形变
        presentView.transform = CGAffineTransform.identity
    }) { (_) in
        // 告诉上下文,动画执行完毕
        transitionContext.completeTransition(true)
    }
}

// 消失的动画
func animateTransitionForDismiss(_ transitionContext: UIViewControllerContextTransitioning) {
    // 1、获取消失的view
    let dismissView = transitionContext.view(forKey: UITransitionContextViewKey.from)!
    // 2、执行动画
    UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: {
        dismissView.transform = CGAffineTransform.init(scaleX: 1.0, y: 0.001)
    }) { (_) in
        dismissView .removeFromSuperview()
        transitionContext.completeTransition(true)
    }
}

}

545792772 143查看 · 1回复 · 2019-1-29 18:12 有用(0
共1个回答
545792772 2019-1-29 18:30 回复

currentVC?.modalPresentationStyle = .custom 写错了..... 改成tipVC 成功....

需要登入后才可以评论 登录 | 立即注册
*滑动验证:
关闭

每日头条

通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| 广东互联网违法和不良信息举报中心|中国互联网举报中心|Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

返回顶部 返回版块