나는 이것에 잠시 붙어있다. 그래서 내 애플 리케이션에서 나는 소리를 재생 버튼을해야합니다. 사용자가 버튼 (button1.png)을 클릭하면 이미지를 (button2.png)로 변경하고 사운드 재생이 끝나면 그림을 원래 이미지로 변경하려고합니다. 콜백이 이것을 설정하는 것이 가장 좋지만 문제가있는 것 같습니다. 도움은 감사 될 것입니다.콜백 함수를 설정하는 방법은 무엇입니까?
여기
#import "ViewController.h"
#import <AudioToolbox/AudioToolbox.h>
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[scrollView setScrollEnabled:YES];
// change setContentSize When making scroll view Bigger and adding more items
[scrollView setContentSize:CGSizeMake(320, 1000)];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - CallBackMethods
#pragma mark - SystemSoundIDs
SystemSoundID sound1;
#pragma mark - Sound Methods
-(void)playSound1
{
NSString* path = [[NSBundle mainBundle]
pathForResource:@"Sound1" ofType:@"wav"];
NSURL* url = [NSURL fileURLWithPath:path];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &sound1);
static void (^callBAck)(SystemSoundID ssID, void *something);
callBAck = ^(SystemSoundID ssID, void *something){
[button1 setImage:@"WhiteButton.png" forState:UIControlStateNormal];
};
AudioServicesAddSystemSoundCompletion(sound1,
NULL,
NULL,
callback,
NULL);
AudioServicesPlaySystemSound(sound1);
}
- (IBAction)button:(id)sender {
NSLog(@"Hello");
[button1 setImage:[UIImage imageNamed:@"ButtonPressed.png"] forState:UIControlStateNormal];
[self playSound1];
}
@end