【问题标题】:iOS 7 Nav Bar SKStoreProductViewControlleriOS 7 导航栏 SKStoreProductViewController
【发布时间】:2017-11-10 08:34:53
【问题描述】:

在 iOS 6 中,引入了 SKStoreProductViewController 以在应用中显示 iTunes Store 项目,因此用户无需离开应用即可查看它们。

到目前为止,我还没有找到自定义这个视图控制器的导航栏的方法。 iOS 6 为黑底灰字,iOS 7 为白底黑字。

有没有办法改变导航栏的色调? (在 iOS 6 和 iOS 7 中)

谢谢。

【问题讨论】:

  • 我看不出这个问题是如何偏离主题或以任何方式显示研究工作太少 -> 没有理由反对或关闭?!

标签: ios objective-c app-store ios7


【解决方案1】:

不是最好的解决方案,但您可以使用 UINavigationBar 的 UIAppearance 方法在显示之前设置颜色:

[[UINavigationBar appearance] setTintColor:[UIColor darkGrayColor]];

SKStoreProductViewController *storeProductViewController = [[SKStoreProductViewController alloc] init];
[storeProductViewController setDelegate:self];
[self presentViewController:storeProductViewController animated:YES completion:nil];

然后在 SKStoreProductViewControllerDelegate 方法中,将其改回原来的样子...

-(void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController {
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    [viewController dismissViewControllerAnimated:YES completion:nil];
}

为我工作。

【讨论】:

  • 这会改变栏的颜色或栏上按钮的颜色吗? (它只是为我改变按钮颜色)
  • @JakeChasan 我很抱歉,误解了这个问题。我遇到的问题,这就是我找到解决这个问题的方法的原因,是我得到了一个带有白色按钮的白色导航栏。
  • 这在 iOS 7 上对我不起作用;不确定 6. 这个问题在 iOS 8 中不存在,但是因为 SKStoreProductViewController 似乎实际上可以使用 UIAppearance 设置。
【解决方案2】:

很遗憾,没有。 SKStoreProductViewControllerremote view controller,这意味着它的视图完全由另一个进程拥有并且无法通过编程方式访问。

这可以通过查看控制器视图的递归描述来确认:

<UIView: 0x8d48da0; frame = (0 0; 320 480); layer = <CALayer: 0x8d48d70>>
   | <_UISizeTrackingView: 0x9b53700; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x9b53770>>
   |    | <_UIRemoteView: 0x9b51d70; frame = (0 0; 320 480); transform = [0.5, -0, 0, 0.5, -0, 0]; userInteractionEnabled = NO; layer = <CALayerHost: 0x9b55ae0>>

_UIRemoteView 表示视图的内容托管在另一个进程中。

【讨论】:

  • 真是一团糟。如果您设置了 [[UINavigationBar 外观] setTintColor:[UIColor someColor]];在您的应用程序中,它确实使用 SKStoreProductViewController 中的该颜色来覆盖默认值,即使它是“远程视图控制器”。但是,设置 [[UINavigationBar 外观] setBarTintColor:[UIColor anotherColor]];对 SKStoreProductViewController 没有影响。 OTOH,条形色调在 MFMailComposeViewController 中工作正常,但您需要使用 [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] 更改按钮颜色。 :(
【解决方案3】:

我在 Appirater rateApp 函数中遇到了这个问题,我是这样解决的:

    //Use the in-app StoreKit view if available (iOS 6) and imported. This works in the simulator.
    if (!_openInAppStore && NSStringFromClass([SKStoreProductViewController class]) != nil) {

        SKStoreProductViewController *storeViewController = [[SKStoreProductViewController alloc] init];
        storeViewController.delegate = self.sharedInstance;

        NSNumber *appId = [NSNumber numberWithInteger:_appId.integerValue];
        [storeViewController loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:appId} completionBlock:^(BOOL result, NSError *error) {
            [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

            id <AppiraterDelegate> delegate = self.sharedInstance.delegate;
            if ([delegate respondsToSelector:@selector(appiraterWillPresentModalView:animated:)]) {
                [delegate appiraterWillPresentModalView:self.sharedInstance animated:_usesAnimation];
            }


            [[self getRootViewController] presentViewController:storeViewController animated:_usesAnimation completion:^{
                [self setModalOpen:YES];
                //Temporarily use a black status bar to match the StoreKit view.
                [self setStatusBarStyle:[UIApplication sharedApplication].statusBarStyle];
                [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent animated:_usesAnimation];

            }];

        }];
    //Use the standard openUrl method if StoreKit is unavailable.
    } else { (...)

【讨论】:

    【解决方案4】:

    您无法自定义栏的颜色,但其默认颜色看起来不错。我发现我的 UIAppearance 设置正在改变文本颜色。

    这是一个 SKStoreProductViewController 子类,它将栏文本颜色设置为默认值,然后在关闭时恢复您的 UIAppearance 设置。如果您从代码中的多个位置进行演示,这很有用。

    @interface GBStoreProductViewController ()
    {
        UIColor *navBarTintColor;
        NSDictionary *navBarTitleTextAttributes;
    }
    
    @end
    
    @implementation GBStoreProductViewController
    
    - (id)init
    {
        UIColor *tintColor = [[UINavigationBar appearance] tintColor];
        NSDictionary *titleTextAttributes = [[UINavigationBar appearance] titleTextAttributes];
        [[UINavigationBar appearance] setTintColor:nil];
        [[UINavigationBar appearance] setTitleTextAttributes:nil];
        if (self = [super init]) {
            navBarTintColor = tintColor;
            navBarTitleTextAttributes = titleTextAttributes;
        }
        return self;
    }
    
    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
    
        [[UINavigationBar appearance] setTintColor:navBarTintColor];
        [[UINavigationBar appearance] setTitleTextAttributes:navBarTitleTextAttributes];
    }
    
    @end
    

    感谢 Kiran Panesar 的技术。

    【讨论】:

      【解决方案5】:

      我也遇到了这个问题,appearance 代码给出的答案对我不起作用。我发现这是修复它的原因,因为我之前在appDelegate 中更改了我的应用程序范围的window.tintColor

      [[UIApplication sharedApplication] keyWindow].tintColor = nil;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-28
        • 2014-09-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多