OGeek|极客世界-中国程序员成长平台

标题: 更改 View Controller 时的 iOS 有线卡住问题 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:49
标题: 更改 View Controller 时的 iOS 有线卡住问题

我有一个 iOS 应用程序,它具有两种在 View Controller 之间更改和导航的方式,第一种方式是使用带有导航 Controller 的 push/pop,第二种方式是使用来自苹果文档的自定义容器 View Controller 的自定义过渡方式,

这是 Storyboard屏幕截图:

enter image description here

在 ViewController.swift 中:

var contentViewController: UIViewController! {
    didSet {
        // remove any previous views
        for view in self.contentView.subviews {
            view.removeFromSuperview()
        }

        // add the view
        // the ViewController must be aded to the children list to avoid being released (as it become a Zombie)
        self.addChildViewController(self.contentViewController)

        if registerDoneFlag {

            //do some animation
            let animation =  CATransition()
            animation.duration = 0.3
            animation.type = kCATransitionPush
            animation.subtype = kCATransitionFromTop
            animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)

            self.contentView.layer.addAnimation(animation, forKey: "SwitchToView1")

            registerDoneFlag = false
        }
        if backFlag {

            //do some animation
            let animation =  CATransition()
            animation.duration = 0.3
            animation.type = kCATransitionPush
            animation.subtype = kCATransitionFromBottom
            animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)

            self.contentView.layer.addAnimation(animation, forKey: "SwitchToView1")

            backFlag = false
        }

        self.contentView.addSubview(self.contentViewController.view)
        self.contentViewController.didMoveToParentViewController(self)
    }
}

我们在应用开始时制作这些动画:

func upperViewAnimation() {

    contianerTop.constant = 0
    UIView.animateWithDuration(0.45, animations: { () -> Void in

        self.view.layoutIfNeeded()

        }, completion:{(finished)  in

            if finished {

                if noInternetConnection && !noInternetConnectionPopup {

                    if isiPadFlag {

                        self.noConnectionViewHeight.constant = 60
                    }
                    else {

                        self.noConnectionViewHeight.constant = 50
                    }

                    UIView.animateWithDuration(0.3, animations: {

                        self.view.layoutIfNeeded()
                    })

                    noInternetConnectionPopup = true

                    openNoInternetConnection()

                }
                else if noInternetConnection {

                    if isiPadFlag {

                        self.noConnectionViewHeight.constant = 60
                    }
                    else {

                        self.noConnectionViewHeight.constant = 50
                    }

                    UIView.animateWithDuration(0.3, animations: {

                        self.view.layoutIfNeeded()
                    })

                }
                else {

                    self.noConnectionViewHeight.constant = 0

                    UIView.animateWithDuration(0.3, animations: {

                        self.view.layoutIfNeeded()

                        }, completion: { (finished) in

                            self.pullToRefreshAction()

                    })


                }

                self.notificationButtonAnimationAndMenuButton()
                self.moreAppsLabel.hidden = false
            }

    })

    //self.notificationButtonAnimationAndMenuButton()

}

除了在某些情况下应用程序进入有线卡住情况外,一切工作正常,导航方式工作正常(推送/弹出)但更改 View Controller 方式根本不起作用,即使应用程序执行了 contentViewController 的设置但不渲染应用程序没有任何变化



Best Answer-推荐答案


当主线程在完整的 View 加载过程中执行服务/网络请求时,我看到了类似的行为。

关于更改 View Controller 时的 iOS 有线卡住问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41999786/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4