1
我一直堅持這一段時間。所以在我的應用程序中,我會有播放聲音的按鈕。當用戶單擊按鈕(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