ViewController.mm 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /****************************************************************************
  2. Copyright (c) 2013 cocos2d-x.org
  3. Copyright (c) 2013-2016 Chukong Technologies Inc.
  4. Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd.
  5. http://www.cocos.com
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated engine source code (the "Software"), a limited,
  8. worldwide, royalty-free, non-assignable, revocable and non-exclusive license
  9. to use Cocos Creator solely to develop games on your target platforms. You shall
  10. not use Cocos Creator software for developing other software or tools that's
  11. used for developing games. You are not granted to publish, distribute,
  12. sublicense, and/or sell copies of Cocos Creator.
  13. The software or tools in this License Agreement are licensed, not sold.
  14. Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. ****************************************************************************/
  23. #import "ViewController.h"
  24. #import "AppDelegate.h"
  25. #import "platform/ios/AppDelegateBridge.h"
  26. //#include "cocos/platform/Device.h"
  27. namespace {
  28. // cc::Device::Orientation _lastOrientation;
  29. }
  30. @interface ViewController ()
  31. @end
  32. @implementation ViewController
  33. - (BOOL) shouldAutorotate {
  34. return YES;
  35. }
  36. //fix not hide status on ios7
  37. - (BOOL)prefersStatusBarHidden {
  38. return YES;
  39. }
  40. // Controls the application's screen edge gesture delay to prevent accidental touches
  41. - (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
  42. {
  43. return UIRectEdgeAll;
  44. }
  45. // Controls the application's preferred home indicator auto-showing otherwise preferredScreenEdgesDeferringSystemGestures is invalidation
  46. - (BOOL)prefersHomeIndicatorAutoHidden {
  47. return NO;
  48. }
  49. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  50. AppDelegate* delegate = [[UIApplication sharedApplication] delegate];
  51. [delegate.appDelegateBridge viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  52. float pixelRatio = [delegate.appDelegateBridge getPixelRatio];
  53. //CAMetalLayer is available on ios8.0, ios-simulator13.0.
  54. CAMetalLayer *layer = (CAMetalLayer *)self.view.layer;
  55. CGSize tsize = CGSizeMake(static_cast<int>(size.width * pixelRatio),
  56. static_cast<int>(size.height * pixelRatio));
  57. layer.drawableSize = tsize;
  58. }
  59. @end