我尝试使用UILabel
传递AudioServicesAddSystemSoundCompletion
,但我无法操纵completionCallback
方法中的值。我使用ARC和Xcode建议添加(_bridge void*)
。
非常感谢任何帮助。
-(void) playWordSound:(UILabel *)label
{
NSString *path;
SystemSoundID soundId;
switch (label.tag)
{
case 1:
..........
break;
}
NSURL *url = [NSURL fileURLWithPath:path];
AudioServicesCreateSystemSoundID( (CFURLRef)objc_unretainedPointer( url), &soundId);
AudioServicesPlaySystemSound(soundId);
AudioServicesAddSystemSoundCompletion (soundId, NULL, NULL,
completionCallback,
(__bridge void*) label);
}
static void completionCallback (SystemSoundID mySSID, void* data) {
NSLog(@"completion Callback");
AudioServicesRemoveSystemSoundCompletion (mySSID);
//the below line is not working
//label.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
}
答案 0 :(得分:3)
在完成处理程序中,标签存储在data
中。你需要__bridge
回来使用它。
static void completionCallback (SystemSoundID mySSID, void* data) {
NSLog(@"completion Callback");
AudioServicesRemoveSystemSoundCompletion (mySSID);
UILabel *label = (__bridge UILabel*)data;
label.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
}