可能的重复:
使 iPhone 振动
我有两个按钮。一键加,一键减。问题是当我在文本区域中输入某个数字(例如 22)时,手机会振动一段时间。这是我的代码:
我想说的是如果标签显示“22”然后振动电话......问题是我该如何写这个......我还在学习,所以任何有关这方面的帮助将不胜感激!到目前为止,这是我的代码:
#import "StartCountViewController.h"
#import "AudioToolbox/AudioServices.h"
@implementation StartCountViewController
int Count=0;
-(void)awakeFromNib {
startCount.text = @"0";
}
- (IBAction)addNumber {
if(Count >= 999) return;
NSString *numValue = [[NSString alloc] initWithFormat:@"%d", Count++];
startCount.text = numValue;
[numValue release];
}
- (IBAction)vibrate {
}
- (IBAction)subtractNumber {
if(Count <= -35) return;
NSString *numValue = [[NSString alloc] initWithFormat:@"%d", Count--];
startCount.text = numValue;
[numValue release];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end