更改 View Controller 时的 iOS 有线卡住问题
<p><p>我有一个 iOS 应用程序,它具有两种在 ViewController 之间更改和导航的方式,第一种方式是使用带有导航 Controller 的 push/pop,第二种方式是使用来自苹果文档的自定义容器 ViewController 的自定义过渡方式, </p>
<p><strong>这是 Storyboard屏幕截图:</strong></p>
<p> <a href="/image/eMNDZ.png" rel="noreferrer noopener nofollow"><img src="/image/eMNDZ.png" alt="enter image description here"/></a> </p>
<p><strong>在 ViewController.swift 中:</strong></p>
<pre><code>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)
}
}
</code></pre>
<p><strong>我们在应用开始时制作这些动画:</strong></p>
<pre><code>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()
}
</code></pre>
<p>除了在某些情况下应用程序进入有线卡住情况外,一切工作正常,导航方式工作正常(推送/弹出)但更改 ViewController 方式根本不起作用,即使应用程序执行了 contentViewController 的设置但不渲染应用程序没有任何变化</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>当主线程在完整的 View 加载过程中执行服务/网络请求时,我看到了类似的行为。</p></p>
<p style="font-size: 20px;">关于更改 ViewController 时的 iOS 有线卡住问题,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/41999786/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/41999786/
</a>
</p>
页:
[1]