我想添加带动画的子视图。我正在使用添加子视图,所以它没有显示任何动画所以我想在我这样做时显示任何动画...我使用下面的代码: -
UIViewController *vControllerHome = [[viewTemp alloc] initWithNibName:@"viewTemp" bundle:nil];
vControllerHome.view.frame =CGRectMake(0, 0, 320, 414);
[self.view addSubview:vControllerHome.view];
self.selectedViewController = vControllerHome;
任何人都可以建议我这样做吗?
答案 0 :(得分:38)
这是代码..试试吧。
PS:将myView
替换为您要替换的视图的名称。
CATransition *applicationLoadViewIn =[CATransition animation];
[applicationLoadViewIn setDuration:duration];
[applicationLoadViewIn setType:kCATransitionReveal];
[applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[[myView layer]addAnimation:applicationLoadViewIn forKey:kCATransitionReveal];
答案 1 :(得分:0)
也许您可以继承UIView并覆盖方法willMove(toSuperview newSuperview: UIView?)
以下是示例:
override public func willMove(toSuperview newSuperview: UIView?) {
super.willMove(toSuperview: newSuperview)
if let _ = newSuperview {
// This view will be added to some view
UIView.animate(withDuration: 0.2, delay: 0.0, usingSpringWithDamping: 0.6, initialSpringVelocity: 30.0, options: .curveEaseInOut, animations: {
//...
}, completion: { (finish) in
})
} else {
// This view will be removed
}
}