traitCollectionDidChange奇怪的行为

时间:2019-12-02 13:19:27

标签: ios swift ios13

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
    super.traitCollectionDidChange(previousTraitCollection)
    if traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {
        print("changed")
    }
}

iOS 13应用程序只是在不更改模式(亮/暗)的情况下进入后台,但调用了“打印”功能。是否可以确定模式真正改变的时刻?

谢谢。

1 个答案:

答案 0 :(得分:1)

我自己也观察到了。
用户界面一切换到后台,就会立即切换-它会立即切换回去。
我想您应该简单地遵循更改并根据需要做出反应。
您可以通过选中add_filter( 'woocommerce_product_tax_class', 'wc_diff_rate_for_user', 1, 2 ); function wc_diff_rate_for_user( $tax_class, $product ) { // not logged in users are not VIP, let's move on... if (!is_user_logged_in()) {return $tax_class;} // this user is not VIP, let's move on... if (!current_user_can( 'VIP' ) ) {return $tax_class;} // it's already Reduced Rate, let's move on.. if ($tax_class == 'Reduced Rate') {return $tax_class;} // let's get all the product category for this product... $terms = get_the_terms( $product->id, 'product_cat' ); foreach ( $terms as $term ) { // checking each category // if it's one of the category we'er looking for if(in_array($term->term_id, array(81,82))) { $tax_class = 'Reduced Rate'; // found it... no need to check other $term break; } } return $tax_class; } 来找到当前的界面样式。
例如:
traitCollection.userInterfaceStyle