2016-02-13 81 views

回答

0

首先,補充一點:

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection { 
    [super traitCollectionDidChange:previousTraitCollection]; 
    if ((self.traitCollection.verticalSizeClass != previousTraitCollection.verticalSizeClass) 
     || (self.traitCollection.horizontalSizeClass != previousTraitCollection.horizontalSizeClass)) { 
     [self setupToolbar:self.traitCollection.horizontalSizeClass]; 
    } 
} 

,然後重新創建工具欄項目:

if (horizontalSizeClass == UIUserInterfaceSizeClassCompact) { 
     mainItems = [NSArray arrayWithObjects:..., nil]; 
    } else { 
     mainItems = [NSArray arrayWithObjects:..., nil]; 
    } 
    [mainToolbar setItems:mainItems animated:NO];