【问题标题】:Why won't this animation selector get called?为什么不调用这个动画选择器?
【发布时间】:2011-10-24 15:52:54
【问题描述】:

好的,我知道有很多这样的问题,但由于某种原因,我无法弄清楚为什么这个回调选择器没有被调用?

这是我添加到新的基于视图的模板中的两种方法。 我将一个按钮链接到 IBAction,并将一个 UIView 链接到 redRect 插座。

动画效果很好,但由于某种我无法弄清楚的原因,没有调用回调。

- (IBAction)toggleView:(id)sender {
    float target;
    if (redRect.alpha == 0.0) target = 1.0;
    else target = 0.0;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationDidStopSelector:@selector(finished)];
    redRect.alpha = target;
    [UIView commitAnimations];
}

- (void)finished {
    NSLog(@"Why won't this get called?");
}

请告诉我我在这里做错了什么 - 这很简单,但我就是想不通。

【问题讨论】:

    标签: iphone animation uiview selector


    【解决方案1】:

    您忘记致电[UIView setAnimationDelegate:]。否则,它怎么知道该给谁打电话?

    【讨论】:

    • 我们都去过那里。苹果最好在没有委托的情况下设置一个警告 NSLog 来设置目标,但是很好(缺点是它会影响性能)。
    【解决方案2】:

    你错过了[UIView setAnimationDelegate:self];

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-18
      • 2013-07-31
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 2019-12-26
      相关资源
      最近更新 更多