1.实现手机震动效果,代码如下:
需要加入AudioToolbox.framework框架,并倒入头文件#import
- (void)viewDidLoad{ [super viewDidLoad]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [btn setTitle:@"点击" forState:UIControlStateNormal]; btn.frame = CGRectMake(100, 100, 200, 50); [btn addTarget:self action:@selector(shake:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn];// Do any additional setup after loading the view, typically from a nib.}- (void)shake:(id)sender{ AudioServicesPlayAlertSound(kSystemSoundID_Vibrate); //kSystemSoundID_Vibrate系统震动}
注意:ipod是不支持震动的。