RootViewController.mm 4.0 KB

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