Animation 添加子视图时显示动画
我想添加带有动画的子视图。我正在使用添加子视图,所以它不显示任何动画,所以我想在执行此操作时显示任何动画。。。我正在使用以下代码:-Animation 添加子视图时显示动画,animation,addsubview,uiviewanimation,uiviewanimationtransition,Animation,Addsubview,Uiviewanimation,Uiviewanimationtransition,我想添加带有动画的子视图。我正在使用添加子视图,所以它不显示任何动画,所以我想在执行此操作时显示任何动画。。。我正在使用以下代码:- UIViewController *vControllerHome = [[viewTemp alloc] initWithNibName:@"viewTemp" bundle:nil]; vControllerHome.view.frame =CGRectMake(0, 0, 320, 414); [self.view addSubview:vControlle
UIViewController *vControllerHome = [[viewTemp alloc] initWithNibName:@"viewTemp" bundle:nil];
vControllerHome.view.frame =CGRectMake(0, 0, 320, 414);
[self.view addSubview:vControllerHome.view];
self.selectedViewController = vControllerHome;
有人能建议我怎么做吗?这是代码。。试试看 PS:Replace
myView
为要替换的视图的名称。
CATransition *applicationLoadViewIn =[CATransition animation];
[applicationLoadViewIn setDuration:duration];
[applicationLoadViewIn setType:kCATransitionReveal];
[applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[[myView layer]addAnimation:applicationLoadViewIn forKey:kCATransitionReveal];
下面是动画块的示例
[UIView transitionWithView:containerView
duration:0.5
options:UIViewAnimationTransitionFlipFromRight //any animation
animations:^ { [containerView addSubview:subview]; }
completion:nil];
也许您可以对UIView进行子类化,并重写方法
willMove(tosuperviewnewsuperview: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
}
}
要删除子视图,请使用相同的代码,但替换[containerView addSubview:subview];使用[self.view removeFromSuperview];