使用 UISwitch 制作动画
我希望能够创建使用 UISwitch 启动的动画。我目前有这段代码可以在开关打开时隐藏一些 UI 元素:
-(IBAction)displayStartingAddress:(id)sender{
NSLog(@"starting displayStartingAddress");
if (enterStartingAddress.hidden==YES) {
enterStartingAddress.hidden=NO;
startingAddress.hidden=NO;
}else{
enterStartingAddress.hidden=YES;
startingAddress.hidden=YES;
}
}
并且我希望开关在显示“enterStartingAddress”和“startingAddress”时对 UI 元素产生动画以将它们向下移动。
我对 iOS 编程和 Objective-C 非常陌生,所以任何帮助将不胜感激。谢谢。
I want to be able to create an animation that is started using a UISwitch. I currently have this code to hide some UI elements when the switch is on:
-(IBAction)displayStartingAddress:(id)sender{
NSLog(@"starting displayStartingAddress");
if (enterStartingAddress.hidden==YES) {
enterStartingAddress.hidden=NO;
startingAddress.hidden=NO;
}else{
enterStartingAddress.hidden=YES;
startingAddress.hidden=YES;
}
}
And I want the switch to cause an animation to the UI elements to move them down when the "enterStartingAddress" and "startingAddress" is shown.
I am very new to iOS programming and Objective-C so any help would be appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您立即将界面元素设置为隐藏,则不会执行任何动画,因为它在动画播放时会被隐藏。您想要做的是为
alpha
属性设置动画。这就是物体的可见性。下面是一个对框架和 alpha 进行动画处理的示例:If you set the interface elements to hidden right away, no animation will be performed because it will be hidden while it's animating. What you want to do is to animate the
alpha
property. That is the visibility of the object. Here is an example of animating the frame and the alpha a bit: