I’ve used two courses one is rootviewcontroller.mm for panorama mode and one other one is rootviewcontrollerV.m (for horizontal) which is inherited from rootviewcontroller.mm.
I’ve acquired the occasion from cocos to ios in appcontroller.mm to vary the orientation – the strategy –
+(void)changeOrientationH:(BOOL)val{
//[AppController scanFingerPrint];
RootViewController* nextViewController = nil;
CCEAGLView* glView = nil;
if(val == NO){
glView = (CCEAGLView *)appController->_viewController.view;
appController->_viewController.view = nil;
appController->_viewControllerV.view = glView;
nextViewController = appController->_viewControllerV;
}
else{
glView = (CCEAGLView *)appController->_viewControllerV.view;
appController->_viewControllerV.view = nil;
appController->_viewController.view = glView;
nextViewController = appController->_viewController;
}
appController->_navController = nil;
appController->_navController = [[UINavigationController alloc]initWithRootViewController:nextViewController];
// Set RootViewController to window
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
// warning: addSubView would not work on iOS6
[appController->window addSubview: appController->_navController.view];
}
else
{
[appController->window setRootViewController:appController->_navController];
// use this methodology on ios6
}
CGRect bounds = [UIScreen mainScreen].bounds;
// NSLog(@"Most important Display screen %@",bounds);
float scale = [[UIScreen mainScreen] scale];
float width = bounds.dimension.width * scale;
float peak = bounds.dimension.peak * scale;
app->updateViewSize(width, peak);
[AppController onOrientationDoneCallback];
//EventDispatcher::dispatchResizeEvent(width, peak);
//cocos2d::EventDispatcher::dispatchResizeEvent(width, peak);
}
I’m additionally including rootviewcontroller file code –
#import “RootViewController.h”
#import “AppController.h”
#import “cocos2d.h”
#embrace “platform/CCApplication.h”
#embrace “platform/ios/CCEAGLView-ios.h”
#embrace “scripting/js-bindings/occasion/EventDispatcher.h”
#embrace “cocos/scripting/js-bindings/jswrapper/SeApi.h”
@interface RootViewController ()
@finish
@implementation RootViewController
// Implement viewDidLoad to do further setup after loading the view, sometimes from a nib.
-
(void)viewDidLoad {
[super viewDidLoad];
NSNumber *worth = [NSNumber numberWithInt:UIInterfaceOrientationMaskLandscapeRight];
[[UIDevice currentDevice] setValue:worth forKey:@“orientation”];
CCEAGLView *view = ((__bridge CCEAGLView *)cocos2d::Software::getInstance()->getView());
self.view = view;
CGRect bounds = [[UIScreen mainScreen] bounds];
UIImageView *backView = [[UIImageView alloc] initWithFrame: bounds];
UIImage *img = [self getLaunchImage];backView.contentMode = UIViewContentModeScaleAspectFit;
[backView setImage:img];
[self.view addSubview:backView];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:true];
}
// For ios6, use supportedInterfaceOrientations & shouldAutorotate as a substitute
#ifdef __IPHONE_6_0
- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
#endif
//- (BOOL) shouldAutorotate {
// return YES;
//}
//
//- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
// [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
//
// CGRect bounds = [UIScreen mainScreen].bounds;
// float scale = [[UIScreen mainScreen] scale];
// float width = bounds.dimension.width * scale;
// float peak = bounds.dimension.peak * scale;
//
// //EventDispatcher::dispatchResizeEvent(width, peak);
// cocos2d::EventDispatcher::dispatchResizeEvent(width, peak);
//}
//repair not conceal standing on ios7
- (BOOL)prefersStatusBarHidden {
return YES;
}
// Controls the applying’s most popular house indicator auto-hiding when this view controller is proven.
-
(BOOL)prefersHomeIndicatorAutoHidden {
return YES;
} -
(void)didReceiveMemoryWarning {
// Releases the view if it doesn’t have a superview.
[super didReceiveMemoryWarning];// Launch any cached knowledge, photos, and so on that aren’t in use.
}
+(BOOL)callNativeUIWithTitle:(NSString *) title andContent:(NSString *)content material{RootViewController *rootVC = [[RootViewController alloc] init];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:content material delegate:rootVC cancelButtonTitle:@“Cancel” otherButtonTitles:@“OK”, nil];
[alertView show];
[alertView release];return true;
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSLog(@“alert clicked”);
// [AppController runJavaScript];
}
-(UIImage *) getLaunchImage
{
NSArray *allPngImageNames = [[NSBundle mainBundle] pathsForResourcesOfType:@“png”
inDirectory:nil];
for (NSString *imgName in allPngImageNames){
// Discover launch photos
if ([imgName containsString:@"LaunchImage"]){
UIImage *img = [UIImage imageNamed:imgName];
// Has picture similar scale and dimensions as our present system's display?
if (img.scale == [UIScreen mainScreen].scale && CGSizeEqualToSize(img.dimension, [UIScreen mainScreen].bounds.dimension)) {
NSLog(@"Discovered launch picture for present system %@", img.description);
return img;
}
}
}
return nil;
}
@finish
and rootviewcontrollerV.m file code —-
//
// RootViewControllerV.m
#import “RootViewControllerV.h”
#import “AppController.h”
@interface RootViewControllerV ()
@finish
@implementation RootViewControllerV
// For ios6, use supportedInterfaceOrientations & shouldAutorotate as a substitute
#ifdef __IPHONE_6_0
- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
#endif
[super viewDidLoad];
// self.view.backgroundColor = UIColor.blueColor;
// Do any further setup after loading the view.
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
//- (void)loadView {
// [super loadView];
//}
/*
#pragma mark – Navigation
// In a storyboard-based software, you’ll typically wish to perform a little preparation earlier than navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the brand new view controller utilizing [segue destinationViewController].
// Go the chosen object to the brand new view controller.
}
*/
@finish
this code is completely working with 2.4.0 with Xcode11 however once I replace from 2.4.0 to 2.4.7, it’s not working