我有一个MasterViewController,我正在一个MasterViewController内添加一个ChildViewController。在MasterViewController内部,我制作了顶部按钮栏,并将其作为容器视图。在此容器视图中,我想移动ChildViewControllers。而且这将发生在MasterViewController中的按钮单击上
这就是我添加ChildViewController的方式
boost::mpl::false_
这些是我的按钮点击
std::bool_constant
我的ChildViewControllers正确膨胀了。但是问题是在按钮上单击。还有另一个视图,我在单击时设置了动画效果,并将其移动到按钮下方。您可以看到我在按钮单击中使用了以下代码。动画开始和结束,将我的相关视图移动到其起始位置。并且没有移动到我的预期区域,请参见下面的代码
func addViewControllerAsChildViewController(childVC : UIViewController) {
oldVC = newVC
childVC.view.frame = viewContainer.bounds
childVC.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
addChildViewController(childVC)
childVC.didMove(toParentViewController: self)
// Where ViewContainer is dedicated area inside the MasterViewController
viewContainer.addSubview(childVC.view)
}
但是这不起作用。但是,如果我注释掉附加了ChildViewController的以下几行内容,则动画会顺利移动并且View会移动到目标区域
@IBAction func onClickBtnNewList(_ sender: UIButton) {
if !(newVC is NewListVC) {
initNewListVC()
addViewControllerAsChildViewController(childVC: targetViewController)
}
UIView.animate(withDuration: 4000, animations: {
self.viewIndicators.frame = sender.frame.offsetBy(dx:0,dy:2)
})
}
@IBAction func onClickBtnSavedList(_ sender: UIButton) {
if !(newVC is SavedListVC) {
initSavedListVC()
addViewControllerAsChildViewController(childVC: targetViewController)
}
UIView.animate(withDuration:400, animations: {
self.viewIndicators.frame = sender.frame.offsetBy(dx:0,dy:2)
})
}
现在您知道为什么会发生吗?可能是什么问题? 我正在使用Xcode 9和Swift 4,请帮助