gpt4 book ai didi

iphone - 使用AudioServicesAddSystemSoundCompletion传递参数

转载 作者:行者123 更新时间:2023-12-01 19:20:23 36 4
gpt4 key购买 nike

我正在尝试通过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];
}

最佳答案

在完成处理程序中,标签存储在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];
}

关于iphone - 使用AudioServicesAddSystemSoundCompletion传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10619588/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com