【发布时间】:2013-08-21 07:01:03
【问题描述】:
我已将 20 个子视图逐行添加到 scrollview 中
yPos=0;
for (int i=0; i<24; i++) {
UIView *timeView=[[UIView alloc]initWithFrame:CGRectMake(71, yPos, 909, 60)];
timeView.userInteractionEnabled=TRUE;
timeView.exclusiveTouch=YES;
timeView.tag=i;
NSLog(@"sub vieww tag=:%d",timeView.tag);
timeView.backgroundColor=[UIColor whiteColor];
UILabel *lbltime=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 70, 60)];
lbltime.text=@"VIEW HERE";
lbltime.textColor=[UIColor grayColor];
// [timeView addSubview:lbltime];
[scrlView addSubview:timeView];
yPos=yPos+61;
}
现在,当我点击子视图时,我不会获得点击的子视图属性。
喜欢坐标。它给出了父视图坐标
我将子视图UserInteractionEnabled 启用为是。
谁能告诉我如何获取点击的子视图坐标和标签值?
【问题讨论】:
-
将点击手势添加到您正在添加的视图中,并为这些视图添加标签,并根据 Tapgetsure 事件方法中的标签识别视图。
-
我建议您编辑帖子以显示您用于处理水龙头的代码。如果您使用的是轻击手势识别器,它附加到什么 - 子视图或滚动视图或什么?
-
在 Tapgetsure 事件中如何获得被点击的视图。
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]; tap.numberOfTapsRequired = 1; [self.view addGestureRecognizer:tap];在事件中-(void)tap:(UITapGestureRecognizer *)recognizer { ....}如何获得被点击的视图。我已经为每个子视图设置了标签 -
我将 SubView 添加到 ScrollView 并将 Scroll 视图添加到父视图
-
UIView *v = Recognizer.view; int tagNum = [v 标签]; tagNum 是你点击视图的标签。
标签: ios uiscrollview subview