如何在iOS中使用动画显示/隐藏UIView?(How to show/hide a UIView with animation in iOS?)

系统教程 行业动态 更新时间:2024-06-14 16:57:18
如何在iOS中使用动画显示/隐藏UIView?(How to show/hide a UIView with animation in iOS?)

主UIView包含两个子视图 - UIView_1和UIView_2 。 在UIView_2 ,有一个按钮可以显示或隐藏UIView_1 。 例如,当用户触摸按钮以显示UIView_1 , UIView_1将滑下, UIView_2将随着转换向下推 。 我对动画知之甚少。 有人可以给我看一些示例代码以供参考吗? 我应该使用CGAffineTransformMakeTranslation吗? 谢谢。

The main UIView contains two subviews - UIView_1 and UIView_2. In the UIView_2, there is a button to show or hide the UIView_1. For example, when a user touches the button to show the UIView_1, then UIView_1 will slide down and UIView_2 will push downwards with transition. I have very little knowledge in animation. Can someone show me some sample code for reference? Should I use CGAffineTransformMakeTranslation? Thanks.

最满意答案

你不需要任何如此复杂的东西。 只需更改视图的帧大小。

NSTimeInterval animationDuration = /* determine length of animation */; CGRect newFrameSize = /* determine what the frame size should be */; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:animationDuration]; theViewToChange.frame = newFrameSize; [UIView commitAnimations];

You don't need anything so complex. Just change the view's frame size.

NSTimeInterval animationDuration = /* determine length of animation */; CGRect newFrameSize = /* determine what the frame size should be */; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:animationDuration]; theViewToChange.frame = newFrameSize; [UIView commitAnimations];

更多推荐

本文发布于:2023-04-12 20:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/e0a211f81da8b65f2451a947df906b0d.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动画   如何在   iOS   UIView   hide

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!