问题在于我无法隐藏条形段。我想删除,因为它在给定时间只有一个段。
如果删除或隐藏UISegmentedControl,则在第一个单元格和导航栏之间保留一个空格。
我不知道哪个观点,我必须改变框架......
$3 = 0x0abbdae0 <UIWindow: 0x9f936b0; frame = (0 0; 320 480); layer = <UIWindowLayer: 0x9f9b420>>
| <UILayoutContainerView: 0xab84630; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0xab96490>>
| | <UITransitionView: 0xab4fe90; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0xab94600>>
| | | <UIViewControllerWrapperView: 0x9fe23f0; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x9fe3170>>
| | | | <UILayoutContainerView: 0x9fe2c90; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x9fb6b00>>
| | | | | <UINavigationTransitionView: 0x9fb6870; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x9fe39b0>>
| | | | | | <UIViewControllerWrapperView: 0x9f0d530; frame = (0 64; 320 416); autoresize = W+H; layer = <CALayer: 0x9f336d0>>
| | | | | | | <UITableView: 0xb301800; frame = (0 0; 320 416); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0xabbdc80>; layer = <CALayer: 0xabc06e0>; contentOffset: {0, -0}>
| | | | | | | | <UITableViewBackgroundView: 0xabc0e70; frame = (0 0; 320 416); autoresize = W+H; layer = <CALayer: 0xabc0ed0>>
| | | | | | | | | <UIImageView: 0xabc0f00; frame = (0 0; 320 416); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0xabc0f60>>
| | | | | | | | | <UIView: 0xabc0fb0; frame = (0 0; 320 416); autoresize = W+H; layer = <CALayer: 0xabc1010>>
| | | | | | | | <UITableViewCell: 0x9f3d010; frame = (0 55; 320 46); text = '1'; autoresize = W; layer = <CALayer: 0x9ff9560>>
我的可见性设置:
[self.SegmentControl removeAllSegments];
if([_invitados count] > 0){
[self.SegmentControl insertSegmentWithTitle:@"SegmentA" atIndex:0 animated:YES];
}
[self.SegmentControl insertSegmentWithTitle:@"SegmentB" atIndex:([self.SegmentControl numberOfSegments]==0 ? 0:1) animated:YES];
if([_followers count] > 0){
[self.SegmentControl insertSegmentWithTitle:@"SegmentC" atIndex:[self.SegmentControl numberOfSegments] animated:YES];
}
[self.SegmentControl setEnabled:YES forSegmentAtIndex:0];
if([self.SegmentControl numberOfSegments]<=1){
[self.SegmentControl removeFromSuperview];
}
答案 0 :(得分:1)
如果您使用自定义UIView,我建议您使用两个功能:[self setNeedsLayout]
和[self layoutSubviews]
。
在layoutSubviews
方法中,您应该设置子视图框架和大小,启用或禁用它们,隐藏等。
在UI中进行一些更改后调用setNeedsLayout
。
来自Apple docs:如果您需要更精确地控制子视图的布局,请执行layoutSubviews
,而不是约束或自动调整行为提供。