<pre name="code" class="objc">- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//开启震动
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
NSLog(@"正在摇一摇");<span style="font-family: Arial, Helvetica, sans-serif;"> num=arc4random()%arrNew.count;</span>
}
- (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//摇动取消
}
- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
//摇动结束
if (event.subtype == UIEventSubtypeMotionShake && arrNew.count!=0) {
//something happens
//完成摇一摇的功能
JiaoModel *jiao=arrNew[num];
[vi sd_setImageWithURL:[NSURL URLWithString:jiao.j_thumb]];
lblTitle.text=jiao.j_subject;
NSLog(@"%d",num);
}else{
//如果没网 不许摇一摇
}
}