traitCollectionDidChange第二次调用失败

时间:2016-08-15 12:02:29

标签: ios

我有以下traitCollectionDidChange

- (void) traitCollectionDidChange:(UITraitCollection *)previousTraitCollection{
    [super traitCollectionDidChange:previousTraitCollection];

    if (previousTraitCollection.horizontalSizeClass != self.traitCollection.horizontalSizeClass){
        NSInteger horizontalClass = self.traitCollection.horizontalSizeClass;
        NSInteger verticalClass = self.traitCollection.verticalSizeClass;
        switch(horizontalClass){
            case UIUserInterfaceSizeClassCompact:
                if (verticalClass == UIUserInterfaceSizeClassRegular){
                    // Setup for iPhone
                }
                break;
            case UIUserInterfaceSizeClassRegular:
                if (verticalClass == UIUserInterfaceSizeClassRegular){
                    // Setup for iPad
                }
                break;

            default:
                break;
        }
    }
}

Update:即使只是转动iPad也会失败。无论何时再次调用该方法,它都会失败:if (previousTraitCollection.horizontalSizeClass != self.traitCollection.horizontalSizeClass){发出错误:[NSConcreteNotification horizo​​ntalSizeClass]:unrecognized selector sent to instance。由于previousTraitCollectionnil

你知道为什么它第二次失败了吗?

0 个答案:

没有答案