【发布时间】:2012-04-23 18:21:45
【问题描述】:
我想在按下 uibutton 时关联一个音效。到目前为止,我已经将一个方法与着陆事件相关联
[allButton addTarget:self action:@selector(showAll) forControlEvents:UIControlEventTouchDownInside];
并在被调用的方法中调用播放声音方法:
- (void)showAll
{
[self.buttonSoundEffect play];
...
}
有没有更好的方法来做到这一点?我可以继承 UIButton 类来处理音效并为我的应用程序特定的每个按钮引用这个新的 UIButton 类吗?
【问题讨论】:
-
如果您在 Interface Builder 中构建界面,那么使用 IBAction 很容易实现。