添加子视图时显示动画

发布于 2024-09-17 19:55:12 字数 372 浏览 5 评论 0原文

我想添加一个带有动画的子视图。我正在使用添加子视图,因此它不显示任何动画,因此我想在执行此操作时显示任何动画...我正在使用下面的代码:-

UIViewController *vControllerHome = [[viewTemp alloc] initWithNibName:@"viewTemp" bundle:nil];
vControllerHome.view.frame =CGRectMake(0, 0, 320, 414);
[self.view addSubview:vControllerHome.view];
self.selectedViewController = vControllerHome;

任何人都可以建议我如何执行此操作吗?

I want to add a subview with animation. I am using add sub view so it is not showing any animation so I want to show any animation when I am doing this... I am using below code :-

UIViewController *vControllerHome = [[viewTemp alloc] initWithNibName:@"viewTemp" bundle:nil];
vControllerHome.view.frame =CGRectMake(0, 0, 320, 414);
[self.view addSubview:vControllerHome.view];
self.selectedViewController = vControllerHome;

Can any one suggest how I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

残花月 2024-09-24 19:55:12

这是代码..试试吧。

PS:将 myView 替换为您要替换的视图的名称。

CATransition *applicationLoadViewIn =[CATransition animation];
[applicationLoadViewIn setDuration:duration];
[applicationLoadViewIn setType:kCATransitionReveal];
[applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[[myView layer]addAnimation:applicationLoadViewIn forKey:kCATransitionReveal];

Here's the code.. Just try it.

PS: Replace myView with the name of the view you want to replace.

CATransition *applicationLoadViewIn =[CATransition animation];
[applicationLoadViewIn setDuration:duration];
[applicationLoadViewIn setType:kCATransitionReveal];
[applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[[myView layer]addAnimation:applicationLoadViewIn forKey:kCATransitionReveal];
全部不再 2024-09-24 19:55:12

这是动画块

[UIView transitionWithView:containerView 
                  duration:0.5 
               options:UIViewAnimationTransitionFlipFromRight //any animation
            animations:^ { [containerView addSubview:subview]; }
            completion:nil];

here is for animation blocks

[UIView transitionWithView:containerView 
                  duration:0.5 
               options:UIViewAnimationTransitionFlipFromRight //any animation
            animations:^ { [containerView addSubview:subview]; }
            completion:nil];
假装不在乎 2024-09-24 19:55:12

也许您可以子类化 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
    }
}

Maybe you can subclass the UIView and override method willMove(toSuperview newSuperview: UIView?)

Here is example:

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
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文