utils.mm 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * utils.mm, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "utils.h"
  11. #import <UIKit/UIKit.h>
  12. namespace
  13. {
  14. UIActivityIndicatorView *indicator;
  15. }
  16. namespace iOS_utils
  17. {
  18. double screenScale()
  19. {
  20. return UIScreen.mainScreen.nativeScale;
  21. }
  22. void showLoadingIndicator()
  23. {
  24. NSCAssert(!indicator, @"activity indicator must be hidden before attempting to show it again");
  25. indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
  26. [indicator startAnimating];
  27. auto mainView = UIApplication.sharedApplication.keyWindow.rootViewController.view;
  28. mainView.userInteractionEnabled = NO;
  29. [mainView addSubview:indicator];
  30. indicator.center = {CGRectGetMidX(mainView.bounds), CGRectGetMidY(mainView.bounds)};
  31. }
  32. void hideLoadingIndicator()
  33. {
  34. indicator.superview.userInteractionEnabled = YES;
  35. [indicator stopAnimating];
  36. [indicator removeFromSuperview];
  37. indicator = nil;
  38. }
  39. void hapticFeedback()
  40. {
  41. auto hapticGen = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
  42. [hapticGen impactOccurred];
  43. }
  44. }