0
私はデバイスを振ると音が出るプログラムを作成しました。ボタンをタップすると、いつでもサウンドが再生されなくなります(これは「リセット」メソッドです)。別のボタンがあります。プッシュすると別のビューが表示されます(これは "infoView"メソッドです)。この問題は、「infoView」に行き、最初のビューに戻るときに発生します。デバイスが揺れても "リセット"ボタンが反応しなくなると、サウンドは再生されます。ここまで私がこれまで持っていたことは、どんな助けも認められるだろう。ビューを切り替えてスイッチバックした後にUIButtonが死んだ
PS。 FirstRespondersと何か関係があるのだろうか?私はまだFirstRespondersの周りに私の頭をラップしようとしています。
の.h
#import <UIKit/UIKit.h>
#import "AVfoundation/AVfoundation.h"
@interface OldTvViewController : UIViewController{
AVAudioPlayer *audioPlayer;
}
-(IBAction)reset;
-(IBAction)infoView:(id)sender;
@end
.M
#import "OldTvViewController.h"
#import "AudioToolBox/AudioToolBox.h"
#import "infoViewController.h"
@implementation OldTvViewController
-(IBAction)infoView:(id)sender{
infoViewController *second = [[infoViewController alloc] initWithNibName:Nil bundle:Nil];
[self presentModalViewController:second animated:YES];
[second release];
}
-(BOOL) canBecomeFirstResponder{
return YES;
}
-(void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
if (event.subtype == UIEventSubtypeMotionShake) {
//Play throw sound
if(audioPlayer.playing){
[audioPlayer stop];
} else{
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/bomb.mp3",[[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = 0;
[audioPlayer play];
}
}
}
-(IBAction)reset{
[audioPlayer stop];
}
-(void)viewDidAppear:(BOOL)animated{
[self becomeFirstResponder];
[super viewDidAppear:animated];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
@end
に追加します。 – vishiphone