在iOS7中,当显示SKStoreProductViewController
时,它会显示状态栏,因此很难点击 [取消] 按钮。
是否可以禁用?
在我的应用中,UIViewControllerBasedStatusBarAppearance
("查看基于控制器的状态栏外观")设置为YES。
答案 0 :(得分:3)
将以下代码放在项目的任何位置:
@interface SKStoreProductViewController (StatusBarFixing)
@end
@implementation SKStoreProductViewController (StatusBarFixing)
-(BOOL) prefersStatusBarHidden { return YES; }
@end
...似乎可以做到这一点,即使它有点粗略。但是,仅当UIViewControllerBasedStatusBarAppearance
设置为YES
答案 1 :(得分:0)
在我看来,状态栏并不打算在这里显示。在我看来,最好只隐藏状态栏,一切看起来都应该如此。
-(void)showAppInAppstore {
SKStoreProductViewController *spvc = [[SKStoreProductViewController alloc] init];
spvc.delegate = self;
// ... start activity indicator here if you wish
__weak typeof(self) weakSelf = self;
[spvc loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier : @(APP_STOREID)}
completionBlock:^(BOOL result, NSError *error) {
// there is no way to stop this task so...
// make sure that user hasn't navigated away from "rate" screen
if(weakSelf != nil && weakSelf.isViewLoaded && weakSelf.view.window != nil) {
// ... stop activity indicator here
if(result == NO || error != nil) {
// handle error if needed
} else {
// Hide status bar
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
// Present store controller
UIViewController *controller = [UIApplication sharedApplication].keyWindow.rootViewController;
[controller presentViewController:spvc animated:YES completion:nil];
}
}
}
];
}
现在确保用户完成后状态栏变为可见
-(void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
[viewController dismissViewControllerAnimated:YES completion:nil];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
}
答案 2 :(得分:0)
您可以继承SKStoreProductViewController
并从该点控制状态栏外观。那简单而优雅。
SKStoreProductViewControllerWithoutStatusBar.h
#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>
@interface SKStoreProductViewControllerWithoutStatusBar : SKStoreProductViewController
@end
SKStoreProductViewControllerWithoutStatusBar.m
import "SKStoreProductViewControllerWithoutStatusBar.h"
@interface SKStoreProductViewControllerWithoutStatusBar ()
@property (nonatomic) BOOL wasStatusBarHidden;
@end
@implementation SKStoreProductViewControllerWithoutStatusBar
// Works if UIViewControllerBasedStatusBarAppearance == NO
- (void)viewWillAppear:(BOOL)animated {
self.wasStatusBarHidden = [[UIApplication sharedApplication] isStatusBarHidden];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[[UIApplication sharedApplication] setStatusBarHidden:self.wasStatusBarHidden withAnimation:UIStatusBarAnimationSlide];
[super viewWillDisappear:animated];
}
// Works if UIViewControllerBasedStatusBarAppearance == YES
- (BOOL)prefersStatusBarHidden {
return YES;
}
@end