ios - cocos2d 横向游戏目前纵向 View Controller

标签 ios view controller cocos2d-iphone

我的游戏使用 cocos2d 横向模式。当我需要展示 View Controller 时,它们也处于横向模式,例如游戏中心和商店 View Controller 。

存储 View Controller 适用于 ios6 及之前的版本(看起来有点奇怪,因为内容仍处于纵向模式),但它在 ios7 上崩溃。游戏中心仍然可以正常工作。

请注意,商店 View Controller 和游戏中心 View Controller 仍然适用于 ios7 上的纵向模式。

那么是否可以将商店 View Controller 设置为仅纵向? (而游戏中心 View Controller 仍处于横向)

我使用这段代码来展示商店 View Controller :

if ([SKStoreProductViewController class] != nil) {
    //create store view controller
    SKStoreProductViewController *productController = [[SKStoreProductViewController alloc] init];
    productController.delegate = (id<SKStoreProductViewControllerDelegate>)self;
    //load product details
    NSDictionary *productParameters = @{SKStoreProductParameterITunesItemIdentifier:url};
    [productController loadProductWithParameters:productParameters completionBlock:^(BOOL result, NSError *error) {
        if (!result) NSLog(@"Error: %@", error);
    }];


    [[(AppController*)[[UIApplication sharedApplication] delegate] navController] presentViewController:productController animated:YES completion:nil];

} else {

    url = [NSString stringWithFormat:@"https://itunes.apple.com/app/id%@?mt=8", url];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

}

上面的 url 是一个 app id 字符串

编辑:

我试过
productController.view.transform = CGAffineTransformMakeRotation(M_PI / 2);

但它仍然在风景中

最佳答案

您可以将 SKStoreProductViewController 子类化,使其仅支持肖像方向,例如

@implementation PortaitStoreProductViewController

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotate
{
    return NO;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
}

然后像这样使用它
SKStoreProductViewController *productController = [[PortaitStoreProductViewController alloc] init];

关于ios - cocos2d 横向游戏目前纵向 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17498941/

相关文章:

Android:检测软键盘打开

AngularJS : access scope object from parent to child

nginx - Kubernetes nginx 入口 Controller 不能上传超过 1mb 的大小

android - phonegap 构建应用程序的 Manifest.xml 和 config.xml 之间的区别

ios - 构建未显示在 iTunes Connect 上

swift - 从 Collection View 重新加载数据时的多 View

android - 在android中使背景变暗

ios - 使用 Swift 在视频中淡入淡出的代码

ios - 从自身创建 NSMutableString 时出现 NSString+Extension 警告

ruby-on-rails - rails : controller won't update model correctly