更改视图控制器的iOS有线冻结问题

时间:2017-02-02 10:30:49

标签: ios objective-c iphone swift

我有一个iOS应用程序,在视图控制器之间有两种更改和导航方式,第一种方法是使用带有导航控制器的push / pop,第二种方法是使用Apple文档中的Custom Container View Controller自定义转换方式,

这是故事板屏幕截图:

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()

}
每个东西都工作得很好,除了在某些情况下应用程序进入有线冻结情况,导航方式工作正常(推/弹)但改变视图控制器方式根本不工作甚至应用程序执行doneViewController的设置但是没有渲染没有应用程序的更改

1 个答案:

答案 0 :(得分:0)

在主线程参与完整视图加载过程中执行服务/ Web请求时,我看到了类似的行为。