【问题标题】:Triggering a method after a delay without abusing [UIView animateWithDuration]?延迟后触发方法而不滥用[UIView animateWithDuration]?
【发布时间】:2011-08-21 10:02:05
【问题描述】:

我有一个 UIViewController 应该控制 2 个 UIImageViews 淡入。

我设法使用 UIView animateWithDuration 方法为它们设置动画,如下所示:

[UIView animateWithDuration:1.5
    animations:^{
      [mFrontpageTitle setAlpha:0];
      [mFrontpageTitle setAlpha:1];
    }
    completion:^(BOOL finished){
      [self AnimatePause];
    }];

-(void)AnimatePause {
[UIView animateWithDuration:5.0
    animations:^{
      [mFrontpageTitle setAlpha:0.99];
      [mFrontpageTitle setAlpha:1];
    }
    completion:^(BOOL finished){
      [self AnimateAuthor];
    }];

触发下一个动画。现在,创建从 .99 到 1.0 的过渡并不是很干净。

是否有更好的方法来触发阻塞或发送消息,只需定义持续时间?

谢谢

祖帕

【问题讨论】:

    标签: objective-c ios timer uiviewanimation


    【解决方案1】:
    NSTimeInterval delay = 1.5; //in seconds
    [self performSelector:@selector(myMethod) withObject:nil afterDelay:delay];
    

    【讨论】:

    • 谢谢。我已经研究了完全错误的方向。如果在间隔完成之前删除 UIView,我会看看这是否会崩溃.. :)
    • 如果我想调用一个带有两个参数的方法怎么办?比如:- (void) MoveSomethigFrom:(id)from To:(id)to;
    • 要么将你的方法包装在只接受一个参数的东西中(例如,一个包含所有参数的字典),要么使用dispatch_after(参见here的例子)。
    猜你喜欢
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 2013-09-25
    • 1970-01-01
    • 2019-06-23
    • 2014-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多