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