很遗憾UIToolbar
不支持UIBarbuttonItem
元素的大小等级。如何在UIBarbuttonItem
上隐藏UIToolbar
小尺寸课程?
答案 0 :(得分: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];