{"action":"created","issue":{"url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/13420","labels_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/13420/labels{/name}","comments_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/13420/comments","events_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/13420/events","html_url":"https://github.com/cocos2d/cocos2d-x/issues/13420","id":101403580,"number":13420,"title":"New device Api to change device orientation programmatically.","user":{"login":"anjandaffo","id":12529102,"avatar_url":"https://avatars.githubusercontent.com/u/12529102?v=3","gravatar_id":"","url":"https://api.github.com/users/anjandaffo","html_url":"https://github.com/anjandaffo","followers_url":"https://api.github.com/users/anjandaffo/followers","following_url":"https://api.github.com/users/anjandaffo/following{/other_user}","gists_url":"https://api.github.com/users/anjandaffo/gists{/gist_id}","starred_url":"https://api.github.com/users/anjandaffo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anjandaffo/subscriptions","organizations_url":"https://api.github.com/users/anjandaffo/orgs","repos_url":"https://api.github.com/users/anjandaffo/repos","events_url":"https://api.github.com/users/anjandaffo/events{/privacy}","received_events_url":"https://api.github.com/users/anjandaffo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/cocos2d/cocos2d-x/labels/module:core","name":"module:core","color":"207de5"},{"url":"https://api.github.com/repos/cocos2d/cocos2d-x/labels/type:feature","name":"type:feature","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-17T11:47:35Z","updated_at":"2015-08-18T06:47:46Z","closed_at":null,"body":"Add a new API in Device or Application level, so developer can change device orientation from anywhere in the application. "},"comment":{"url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/comments/132092126","html_url":"https://github.com/cocos2d/cocos2d-x/issues/13420#issuecomment-132092126","issue_url":"https://api.github.com/repos/cocos2d/cocos2d-x/issues/13420","id":132092126,"user":{"login":"anjandaffo","id":12529102,"avatar_url":"https://avatars.githubusercontent.com/u/12529102?v=3","gravatar_id":"","url":"https://api.github.com/users/anjandaffo","html_url":"https://github.com/anjandaffo","followers_url":"https://api.github.com/users/anjandaffo/followers","following_url":"https://api.github.com/users/anjandaffo/following{/other_user}","gists_url":"https://api.github.com/users/anjandaffo/gists{/gist_id}","starred_url":"https://api.github.com/users/anjandaffo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anjandaffo/subscriptions","organizations_url":"https://api.github.com/users/anjandaffo/orgs","repos_url":"https://api.github.com/users/anjandaffo/repos","events_url":"https://api.github.com/users/anjandaffo/events{/privacy}","received_events_url":"https://api.github.com/users/anjandaffo/received_events","type":"User","site_admin":false},"created_at":"2015-08-18T06:47:45Z","updated_at":"2015-08-18T06:47:45Z","body":"@zilongshanren  Thanks for your response.\r\n\r\nOne of my project having few screen design in portrait mode and few screen in landscape mode. It's client requirement. Before pushScene or replaceScreen I need to change orientation. for UI layout I design the scenes as respective of screen width and height. So UI not getting issue. I achieve the goal by following ways: If you have any better solution suggest me.\r\n\r\nOn click of button I make a call to Android Java using JNI and iOS  for programmatically change the device orientation.following methods programmatically changed the device orientation.\r\n\r\nAndroid: \r\npublic static void changeOrientation(boolean isPortrait) {\r\n    \tint orientation;\r\n    \tif (isPortrait) {\r\n\t\t\torientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;\r\n\t\t} else {\r\n\t\t\torientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;\r\n\t\t}\r\n\t\tinstance.activity.setRequestedOrientation(orientation);\r\n\t}\r\n\r\niOS:\r\n\r\n- (void) changeOrientation:(bool)isPortrait {\r\n    NSNumber *value;\r\n    _isPortrait = isPortrait;\r\n    if (isPortrait) {\r\n        value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];\r\n    }\r\n    else {\r\n        value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];\r\n    }\r\n    \r\n    [[UIDevice currentDevice] setValue:value forKey:@\"orientation\"];\r\n}\r\n\r\nwhere _isPortrait is declared global boolean property.\r\n\r\nAdd below lines in supportedInterfaceOrientations method of RootViewController.mm\r\nif (_isPortrait) {\r\n        return UIInterfaceOrientationMaskPortrait;\r\n    } else {\r\n        return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;\r\n    }\r\n\r\nI found a method \"applicationScreenSizeChanged\" In CCApplication-android.cpp and CCApplication-ios.mm with new screen height and width. I added following code in below method\r\n\r\nauto director = cocos2d::Director::getInstance();\r\n    auto glview = director->getOpenGLView();\r\n    if (glview)\r\n    {\r\n        glview->setFrameSize(newWidth,newHeight);\r\n        glview->setDesignResolutionSize(newWidth,newHeight, ResolutionPolicy::FIXED_WIDTH);\r\n    }\r\n    cocos2d::NotificationCenter::getInstance()->postNotification(\"ORIENTATION_CHANGED\", NULL);\r\n\r\nHere I send a postNotification to observe notification in cpp side. So I will push/replace scene after observe notification. I think better is If there are callback. \r\n\r\nIf a new API having callback so I don't need to postNotification.\r\n\r\nAny suggestions by you are most welcome.\r\n\r\nThanks"}}