我有一个 NSTimer 应该每秒调用一个方法,但它似乎根本没有调用它。
这就是我声明计时器的方式:
[NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(fadeManager:) userInfo:nil repeats:YES];
这是它调用的方法:
-(void) fadeManager: (NSTimer*) timer{
NSLog(@"IT'S WORKING!");
self.playHead += .1; // keeps track of where they are in full track
if (self.playHead >= self.wait && ![player isPlaying]) { // checks if wait is over
[player play];
}
if (self.playHead >= self.duration + self.startTime && [player isPlaying]) { // checks if full duration is over
[player pause];
[self reset];
}
int fadeOutArea = self.startTime + self.duration - self.fadeOut;
int fadeInArea = self.startTime + self.fadeIn;
if (self.playHead <= fadeInArea && [player volume] < relativeVolume) { // checks if fadingIn.
[self fadeInIncriment];
}
if (self.playHead >= fadeOutArea && [player volume] > 0) {
[self fadeOutIncriment];
}
}
代码不起作用,所以我把 NSLog 和一个断点都放进去了。似乎它永远不会被调用。为什么是这样?我在 .m 文件中声明该方法是否重要:
#import <AVFoundation/AVFoundation.h>
@interface CueMusic ()
- (void) delayFadeOut: (AVAudioPlayer*) dFade;
- (void) fadeInIncriment;
- (void) fadeOutIncriment;
- (void) fadeManager: (NSTimer*) timer; // <--------
- (void) start;
@end
@implementation CueMusic
.......