iOS晃动检测
2020年02月15日
作者:佚名
下面是来客网 jb51.cc 通过网络收集整理的代码片段。
来客网小编现在分享给大家,也给大家做个参考。
1、在AppDelegate.h中进行如下设置: 1. -(BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions 2. { 3. application.applicationSupportsShakeToEdit = YES; 4. } 2、在你需要对晃动事件进行处理的ViewController中添加如下代码: 1. -(BOOL)canBecomeFirstResponder{ 2. return YES; 3. } 4. 5. -(void)viewDidAppear:(BOOL)animated{ 6. [super viewDidAppear:animated]; 7. [self becomeFirstResponder]; 8. } 9. 10. - (void)viewWillDisappear:(BOOL)animated{ 11. [self resignFirstResponder]; 12. [super viewWillDisappear:animated]; 13. } 14. 15. -(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event 16. { 17. if (motion == UIEventSubtypeMotionShake) { 18. 19. 在这里写晃动时 触动的事件 20. } 21. }
以上是来客网(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。
以上是来客网为你收集整理的iOS晃动检测全部内容,希望文章能够帮你解决iOS晃动检测所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。