开发者

selecting next row of table view by shaking the iPhone

I want to change the row selection by shaking my iphone. i.e. as soon 开发者_开发技巧as I shake my iphone, the next row should be selected of tableview. And according to that another operation should be perform. can any one tell???


Apple's iPhone Human Interface Guidelines warn against defining your own meaning for the shake gesture:

Avoid overloading the shake gesture. Even though you can programmatically set when your application interprets a shake event as shake to undo, you run the risk of confusing users if they also use shake to perform a different action.

For how to actually use the Shake iPhone API, here's a similar question


Use an UIAccelerometer. Implement the UIAccelerometerDelegate protocol, and do something like

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
  UIAccelerationValue threshold = 2.0;
  if ((fabsf(acceleration.x) > threshold) || (fabsf(acceleration.y) > threshold) || (fabsfacceleration.z) > threshold) {
    [self advanceRow];
  }
}

with an appropriately defined -[YourClass advanceRow]. Try out different values for threshold for a sensitive wiggle or a violent shake.

But also see this answer: how to detect and program around shakes for the iphone

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜