进入游戏大厅强制横屏,进入游戏中强制竖屏。
之前用了一种方法
if([[UIDevice currentDevice]respondsToSelector:@selector(setOrientation:)]) {
[[UIDevice currentDevice]performSelector:@selector(setOrientation:)
withObject:(id)UIInterfaceOrientationPortrait];
}
后来被告知这个方法在ios3.0后被私有化了 调用这个方法将会过不了审
后来又用
- (void)setOrientation:(BOOL)fullscreen {
if (fullscreen) {
NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
[[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@“orientation”];
NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:orientationTarget forKey:@“orientation”];
} else {
NSNumber *resetOrientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
[[UIDevice currentDevice] setValue:resetOrientationTarget forKey:@“orientation”];
NSNumber *orientationTarget = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:orientationTarget forKey:@“orientation”];
}
}
调试时发现切换无效
游戏构建ios的时候勾选了Portrait,LandscapeLeft,LandscapeRight 三个选项 于是游戏启动的时候就会强制变成竖屏
焦头烂额了
emmmmmmmmmm
你应该在代码里面设置横竖屏,不应该勾选
就是构建的时候一个选项都不选 然后在ios底层设置么
我用到横竖屏,一开始是竖屏的,我就只勾选竖屏,就保证了启动的时候不会横屏
而我的根控制器是tabbarController,我在里面重写了这些
我根据点击按钮旋转方向,点之前改变tabbar的展示方向,再通过方法旋转
一开始开机的屏幕是什么方向,勾选的时候就只需选那个方向就行了
而调用这些方法时候,不是方法无效,而是方法生效了,但是你没有在你当前的控制器里面重写屏幕支持和展示方向,一般都是默认的方向,所以看起来是无效的
因为是初始场景是横屏 我就在构建的时候勾选了横屏的选项 在跳转竖屏场景的时候还是没有效果···是因为我还有哪里没有完善的么
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation这个方法重写了吗
还是说要新建一个view来对竖屏进行支持
我一开始就用的新建view的方法 发现在ipx上一下就看出并不是真正实现切换 ipx的虚拟bar还是根据手机的横竖屏格式放置的 只是一个view布局的旋转
(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation重写了
游戏打开是竖屏 进入初始场景的时候会有一瞬间是横屏 然后又跳成竖屏···
这个不是当前控制器支持的方向么 我跳转竖屏的时候不是要支持竖屏方向么
你应该在旋转的时候改变支持方向,而不是把支持方向全写上去,当你是横屏的时候,就不应该支持竖屏,你点击切换方向为竖屏的时候,就不应该支持横屏