首次调用时未显示动画 [英] Animation not Shown When Calling it First Time

查看:72
本文介绍了首次调用时未显示动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的动画:

- (void)showMenu
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelay:0.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    self.scrollView.frame = CGRectMake(296, -150, 432, 356);

    [self.buttonMenu setImage:[UIImage imageNamed:@"menu_arrow_up.png"] forState:UIControlStateNormal];
    [self.view bringSubviewToFront:self.scrollView];

    [UIView commitAnimations];
}

当我第一次调用此动画时,仅按钮的图像发生变化,我的滚动视图的位置没有改变.

When I call this animation the first time, just the image of my button changes, the position of my scrollview does not change.

在两次调用 showMenu 方法之后,一切正常.

Everything works correctly, after I called my showMenu method twice.

  • 我叫 showMenu .按钮的图像改变. scrollview 的位置不是
  • 我调用了另一种方法来重置所有内容.按钮更改的图像. scrollview 的位置不是
  • 我叫 showMenu .按钮的图像改变. scrollview 的位置更改
  • 从现在开始,每当我调用 showmenu
  • I call showMenu. the image of the button changes. position of scrollview not
  • I call another method to reset everything. image of button changes. position of scrollview not
  • I call showMenu. the image of the button changes. position of scrollview changes
  • from now on it works every time I call showmenu

第二种方法是 closeMenu :

- (void)closeMenu
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelay:0.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    self.scrollView.frame = CGRectMake(296, -317, 432, 356);

    [self.buttonMenu setImage:[UIImage imageNamed:@"menu_arrow_down.png"] forState:UIControlStateNormal];

    [UIView commitAnimations];
}

那为什么只单击两次就可以正常工作呢?

So why does it work just when I click it twice?

推荐答案

我执行UIAnimation并以编程方式同时添加UITableView时遇到相同的问题.UIView的框架已更改,但不会在显示中更新.要解决此问题,请使用

I had the same problem when i perform a UIAnimation and simultaneously adding a UITableView programmatically. The frame of UIView changes but it will not update in display. To solve this problem call your method using

Blockquote

Blockquote

-performSelector:withObject:afterDelay:,延迟为0.

它将解决您的问题.

这篇关于首次调用时未显示动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆