在为视图添加动画效果时为 UIButton 添加动画效果
我在动画中面临一个问题。
所以现在在我的应用程序中,我有一个带有关闭按钮的子视图。按下关闭按钮时,会出现卷曲动画,显示上一个视图。这是正常工作的。我通过将通知传递给 NSNotificationCenter 来执行卷曲关闭动画,如下所示 [[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:self];
现在我想将动画应用于关闭按钮本身,以便当我按下关闭按钮时,它会执行动画并且会发生卷曲动画。所以我的方法是通过以下代码
[UIView transitionWithView:self.view.superview duration:1
options:UIViewAnimationOptionCurveEaseIn
animations:^ {
closeButton.frame = CGRectMake(500, 15, 100, 40); }
completion:nil];
,其中 closeButton.frame 的值为 (580,15,100,40),因此动画就像图像从右向左从 580 移动到 500 一样。
那么会发生什么当我运行代码时,当我按下关闭按钮时,关闭按钮动画不会发生,但会发生卷曲动画。因此,为了测试,当我注释掉发布通知的代码时,关闭按钮动画效果完美,但向下卷曲动画不会发生,也不会出现上一个视图(因为我不发送会导致视图的通知)关闭)。
我想知道这里出了什么问题以及为什么它不允许两个动画同时发生。
I am facing a problem in animation.
So right now in my app, I have a subview which has a close button. When the close button is pressed, a curl down animation occurs showing the previous view. That is working properly. I perform the curl down closing animation by passing a notification to the NSNotificationCenter like this [[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:self];
Now I wanted to apply an animation to the close button itself so that when I press the close button, it would perform an animation as well as the curl down animation would occur. So the way I do it is by the following code
[UIView transitionWithView:self.view.superview duration:1
options:UIViewAnimationOptionCurveEaseIn
animations:^ {
closeButton.frame = CGRectMake(500, 15, 100, 40); }
completion:nil];
Where previously the closeButton.frame had the value of (580,15,100,40) so the animation would be like the image was moving from right to left from 580 to 500.
So what happens when I run the code is that when I press the close button, the close button animation does not happen but the curl down animation occurs. So for testing when I commented out the code where I post the notification, the close button animation works perfectly but the curl down animation does not happen nor does the previous view come up ( since I do not send a notification which would cause the view to close).
I would like to know what is going wrong here and why it does not allow 2 animations to occur at the same time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我解决问题的方法...
我使用了嵌套动画,其中我在关闭按钮动画的完成部分中包含了用于向下卷曲关闭视图的代码...
Here is how I solved it...
I used the nested animation using blocks where I included the code for the curl down close view in the completion part of the close button animation...