- 在 UIResponder中存在这么一套方法
- - (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
-
http://www.kmnk01.com/hxpfk/2015/dyxf_1123/86.html http://www.kmnk01.com/hxpfk/2015/zf_1123/87.html - - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
- - (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
- 这就是执行摇一摇的方法。那么怎么用这些方法呢?
- 很简单,你只需要让这个Controller本身支持摇动
- 同时让他成为第一相应者:
- - (void)viewDidLoad
- {
-
http://www.kmnk01.com/hxpfk/2015/bdy_1123/88.html http://www.kmnk01.com/hxpfk/2015/pfsy_1123/89.html - [superviewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- [[UIApplicationsharedApplication] setApplicationSupportsShakeToEdit:YES];
- [selfbecomeFirstResponder];
- }
- 然后去实现那几个方法就可以了
- - (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
- {
- //检测到摇动
-
http://www.kmnk01.com/hxpfk/2015/bt_1123/90.html http://www.kmnk01.com/hxpfk/2015/bt_1123/91.html - }
- - (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
- {
- //摇动取消
-
http://www.kmnk01.com/hxpfk/2015/bt_1123/92.html http://www.kmnk01.com/hxpfk/2015/gm_1123/93.html - }
- - (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
- {
- //摇动结束
- if (event.subtype == UIEventSubtypeMotionShake) {
-
http://www.kmnk01.com/hxpfk/2015/hzj_1123/94.html http://www.kmnk01.com/hxpfk/2015/hzj_1123/95.html - //something happens
- }
- }
[IOS开发教程] IOS端的摇一摇功能
最新推荐文章于 2022-03-25 11:14:14 发布