uisegmentedcontrol 未检测到某些段上的触摸
Posted
技术标签:
【中文标题】uisegmentedcontrol 未检测到某些段上的触摸【英文标题】:uisegmentedcontrol doesn't detect touch on certain segments 【发布时间】:2011-11-07 19:46:07 【问题描述】:我在水平滚动的 uiscrollview 中有一个 uisegmentedcontrol。滚动视图工作正常,内容根据分段控件的宽度调整大小。分段控件检测对首次显示时可见的那些段的触摸。如果我向右滚动,我将无法选择新显示的段。 cuttof 也不完全是一个片段,它最初显示的是什么,就像有一个视图剪辑它一样。感谢您的帮助,我已从滚动视图中取消选择剪辑子视图。
// creates segmented control to indicate test to show on graph
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:self.labels];
segmentedControl.frame = CGRectMake(15, 41, 285, 30);
segmentedControl.autoresizingMask =
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.selectedSegmentIndex = 0;
segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[segmentedControl addTarget:self action:@selector(testChange:) forControlEvents:UIControlEventValueChanged];
//checks the length of the text in each segment and asjusts control accordingly
int x = 0;
segmentWidth = 0.0;
for (id segment in [segmentedControl subviews])
for (id label in [segment subviews])
if ([label isKindOfClass:[UILabel class]])
[label setTextAlignment:UITextAlignmentCenter];
[label setFont:[UIFont boldSystemFontOfSize:12]];
CGFloat textWidth = [[segmentedControl titleForSegmentAtIndex:x] sizeWithFont:[UIFont boldSystemFontOfSize:12.0]].width + 20;
[segmentedControl setWidth:textWidth forSegmentAtIndex:x];
segmentWidth += textWidth;
x++;
self.testSegment = segmentedControl;
[segmentedControl release];
//adds segmentedcontroll to scrollview, and adjusts contensize
[scrollView setContentSize:CGSizeMake(segmentWidth + 45, scrollView.frame.size.height)];
[scrollView showsHorizontalScrollIndicator];
[scrollView addSubview:testSegment];
【问题讨论】:
【参考方案1】:已修复,问题是我在计算每个段的宽度之前设置了分段控件的框架。
segmentedControl.frame = CGRectMake(15, 41, segmentWidth+20, 30);
之前
self.testSegment = segmentedControl;
【讨论】:
以上是关于uisegmentedcontrol 未检测到某些段上的触摸的主要内容,如果未能解决你的问题,请参考以下文章
MutationObservers - 未检测到添加的某些节点
为啥执行某些命令后 Pexpect 会间歇性挂起(未检测到 EOF)?
从 UITableView didSelectRowAtIndexPath 检测 UISegmentedControl 中的选择更改