私はに取り組んでいbuzzer app for IOS
ます。するとclick the buzzer
、ブザーが鳴り、30 seconds
ポップアップし、カウントダウンしてからafter 1
ブザーが鳴り、消えます。の途中で30-second countdown
誰かがブザーをリセットしたい場合 (タイマーが鳴って消えるようにするため) は、 をクリックするだけbuzzer again
です。
3 つの質問が
あります。1. UILabel を非表示にしてアプリを起動し、最初のクリックで表示するにはどうすればよいですか?
2. 30 秒のカウントダウン中にブザーをクリックしてリセットするにはどうすればよいですか?
3. ブザーをリセットすると、複数回クリックしたときにタイマーが非常に速く下がる問題は修正されますか?
viewcontrol.h
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
@interface ViewController : UIViewController {
IBOutlet UILabel *seconds;
NSTimer *timer;
int MainInt;
SystemSoundID buzzer;
}
- (IBAction)start:(id)sender;
- (void)countdown;
@end
ViewController.m #import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(IBAction)start:(id)sender {
seconds.hidden = NO;
MainInt = 30;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countdown) userInfo:nil repeats:YES];
AudioServicesPlaySystemSound(buzzer);
}
-(void)countdown {
MainInt -= 1;
seconds.text = [NSString stringWithFormat:@"%i", MainInt];
if (MainInt < 1) {
[timer invalidate];
timer = nil;
seconds.hidden = YES;
AudioServicesPlaySystemSound(buzzer);
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSURL *buttonURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Buzz" ofType:@"wav"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)buttonURL, &buzzer);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end