RootViewController.mm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /****************************************************************************
  2. Copyright (c) 2013 cocos2d-x.org
  3. Copyright (c) 2013-2016 Chukong Technologies Inc.
  4. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. ****************************************************************************/
  22. #import "RootViewController.h"
  23. #import "cocos2d.h"
  24. #import "platform/ios/CCEAGLView-ios.h"
  25. @implementation RootViewController
  26. /*
  27. // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
  28. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  29. if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
  30. // Custom initialization
  31. }
  32. return self;
  33. }
  34. */
  35. // Implement loadView to create a view hierarchy programmatically, without using a nib.
  36. - (void)loadView {
  37. // Initialize the CCEAGLView
  38. CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [UIScreen mainScreen].bounds
  39. pixelFormat: (__bridge NSString *)cocos2d::GLViewImpl::_pixelFormat
  40. depthFormat: cocos2d::GLViewImpl::_depthFormat
  41. preserveBackbuffer: NO
  42. sharegroup: nil
  43. multiSampling: cocos2d::GLViewImpl::_multisamplingCount > 0 ? YES : NO
  44. numberOfSamples: cocos2d::GLViewImpl::_multisamplingCount ];
  45. // Enable or disable multiple touches
  46. [eaglView setMultipleTouchEnabled:NO];
  47. // Set EAGLView as view of RootViewController
  48. self.view = eaglView;
  49. }
  50. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  51. - (void)viewDidLoad {
  52. [super viewDidLoad];
  53. }
  54. - (void)viewWillAppear:(BOOL)animated {
  55. [super viewWillAppear:animated];
  56. }
  57. - (void)viewDidDisappear:(BOOL)animated {
  58. [super viewDidDisappear:animated];
  59. }
  60. // For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
  61. #ifdef __IPHONE_6_0
  62. - (NSUInteger) supportedInterfaceOrientations{
  63. return UIInterfaceOrientationMaskAllButUpsideDown;
  64. }
  65. #endif
  66. - (BOOL) shouldAutorotate {
  67. return YES;
  68. }
  69. - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
  70. [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
  71. auto glview = cocos2d::Director::getInstance()->getOpenGLView();
  72. if (glview)
  73. {
  74. CCEAGLView *eaglview = (__bridge CCEAGLView *)glview->getEAGLView();
  75. if (eaglview)
  76. {
  77. CGSize s = CGSizeMake([eaglview getWidth], [eaglview getHeight]);
  78. cocos2d::Application::getInstance()->applicationScreenSizeChanged((int) s.width, (int) s.height);
  79. }
  80. }
  81. }
  82. //fix not hide status on ios7
  83. - (BOOL)prefersStatusBarHidden {
  84. return YES;
  85. }
  86. // Controls the application's preferred home indicator auto-hiding when this view controller is shown.
  87. - (BOOL)prefersHomeIndicatorAutoHidden {
  88. return YES;
  89. }
  90. - (void)didReceiveMemoryWarning {
  91. // Releases the view if it doesn't have a superview.
  92. [super didReceiveMemoryWarning];
  93. // Release any cached data, images, etc that aren't in use.
  94. }
  95. @end