最近公司接了个棋牌 有一个问题 开始的两个界面是竖屏的 但是进入游戏后是横屏的 有没有大神教我个方法 跪求!!!!
自己顶
自己顶
再顶!!!
121
web:cocos有接口了,直接使用
ios:
AppComtorller.mm加这个函数
// 设置屏幕方向
+(void) setOrientation:(NSNumber *) orientation {
NSNumber *orientationTarget;
NSNumber * landscape = [NSNumber numberWithInt:1];
NSNumber * portrait = [NSNumber numberWithInt:2];
if ([orientation isEqualToNumber:landscape]) {
orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:orientationTarget forKey:@“orientation”];
} else if ([orientation isEqualToNumber:portrait]){
orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:orientationTarget forKey:@“orientation”];
}
}
RootViewController.mm
+(void) setCurOrientation:(NSNumber * ) orientation {
curOrientation = orientation;
}
// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
#ifdef __IPHONE_6_0
- (NSUInteger) supportedInterfaceOrientations{//这是修改原来的函数,不是新加的
NSNumber * landscape = [NSNumber numberWithInt:1];
if ([curOrientation isEqualToNumber:landscape]) {
return UIInterfaceOrientationMaskLandscape;
} else {
return UIInterfaceOrientationMaskPortrait;
}
//return UIInterfaceOrientationMaskAllButUpsideDown;
//return UIInterfaceOrientationMaskLandscape;
}
#endif
安卓
// 设置屏幕方向
public static void setOrientation(int orientation){
switch(orientation)
{
case 1://横屏
instance.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
break;
case 2://竖屏
instance.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
break;
}
}
使用方法:
if (cc.sys.os === cc.sys.OS_IOS) {
var ret = jsb.reflection.callStaticMethod(“RootViewController”,
“setCurOrientation:”, chasingOrientation);
cc.view.setFrameSize(changeSize.width, changeSize.height);
jsb.reflection.callStaticMethod(“AppController”,
“setOrientation:”, chasingOrientation);
} else if (cc.sys.os === cc.sys.OS_ANDROID) {
jsb.reflection.callStaticMethod(“org/cocos2dx/javascript/AppActivity”, “setOrientation”, “(I)V”, chasingOrientation);
cc.view.setFrameSize(changeSize.width, changeSize.height);
}
大致思路是这样,可以看这里https://github.com/linguitang/cocos2d-x-lite/tree/develop/templates/js-template-link/frameworks/runtime-src
老哥,已经实现了嘛,可以介绍点经验吗?
我写的跟你的差不多,但是切换成功以后,按钮都点击不了
需要改适配层的代码,他屏幕尺寸没计算好
切换成后,scene如何处理,重新初始化吗? 还是有个方法重新布局ui?