1

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

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

请注意,商店视图控制器和游戏中心视图控制器仍然适用于 ios7 上的纵向模式。

那么是否可以将商店视图控制器设置为仅纵向?(而游戏中心视图控制器仍处于横向)

我使用这段代码来展示商店视图控制器:

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);

但它仍然在风景中

4

1 回答 1

3

您可以将 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];
于 2013-07-09T07:22:09.263 回答