在iOS上使用多个NSTimers - 只有一个计时器触发

需要帮助解决问题。 目标 我正在整理一个iOS书籍应用程序,它使用NSTimers在加载视图后触发几个交错的动画事件。我已经创建了一个MethodCallerWithTimer类来帮助我这样做(底部的代码)。 我的解决方案至今 当我使用MethodCallerWithTimer类时,我将objectOwningMethod指定为我的UIViewController子类对象(它是一个书页),然后将该方法作为该类中的实例方法。以下是我指定的方法示例 - 只需在屏幕上打开一些艺术作品:
- (void) playEmory {
   [emoryRedArt setHidden:NO];
}
我的问题 当我创建多个MethodCallerWithTimer实例然后加载视图并启动它们时,我只会发生FIRST事件。没有其他计时器调用他们的目标方法。我怀疑我不明白我要求NSRunLoop做什么或类似的东西。 有什么想法吗? 这是我的MethodCallerWithTimer类:
@interface MethodCallerWithTimer : NSObject {
    NSTimer * timer;
    NSInvocation * methodInvocationObject;
    NSNumber * timeLengthInMS;
}

- (id) initWithObject: (id) objectOwningMethod AndMethodToCall: (SEL) method;
- (void) setTime: (int) milliseconds;
- (void) startTimer;
- (void) cancelTimer;

@end
并实施:
#import "MethodCallerWithTimer.h"

@implementation MethodCallerWithTimer

- (id) initWithObject: (id) objectOwningMethod AndMethodToCall: (SEL) method {
    NSMethodSignature * methSig = [[objectOwningMethod class] instanceMethodSignatureForSelector:method];
    methodInvocationObject = [NSInvocation invocationWithMethodSignature:methSig];
    [methodInvocationObject setTarget:objectOwningMethod];
    [methodInvocationObject setSelector:method];
    [methSig release];
    return [super init];
}
- (void) setTime: (int) milliseconds {
    timeLengthInMS = [[NSNumber alloc] initWithInt:milliseconds];
}
- (void) startTimer {
    timer = [NSTimer scheduledTimerWithTimeInterval:([timeLengthInMS longValue]*0.001) invocation:methodInvocationObject repeats:NO];
}
- (void) cancelTimer {
    [timer invalidate];
}
-(void) dealloc {
    [timer release];
    [methodInvocationObject release];
    [timeLengthInMS release];
    [super dealloc];
}

@end
    
已邀请:
这些看起来像是延迟后的一次性发射;你考虑过使用类似的东西:
[myObject performSelector:@selector(playEmory) withObject:nil afterDelay:myDelay];
其中
myObject
是具有
playEmory
例程的实例,
myDelay
是您希望操作系统在拨打电话之前等待的秒数的
float
? 你可以在这里找到关于这种味道的更多信息。     

要回复问题请先登录注册