【发布时间】:2020-05-16 20:39:53
【问题描述】:
我用 XIB 添加了自定义 UIView。我只是尝试执行按钮操作和点击手势,即使为包括 ContentView 在内的所有元素启用了用户交互,也没有任何效果。
初始化 UIView
-(void)initializeSubviews {
self.backgroundColor = [UIColor clearColor];
[[[NSBundle mainBundle]loadNibNamed:@"DatesView" owner:self options:nil]firstObject];
[self addSubview:self.contentView];
// self.contentView.frame = self.bounds;
[self.fromDateButton addTarget:self action:@selector(tapOnfromDate:) forControlEvents:UIControlEventTouchUpInside];
self.fromDateButton.backgroundColor = [UIColor redColor];
}
点击手势
UITapGestureRecognizer *fromDateTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnfromDate)];
[datesView.contentView addGestureRecognizer:fromDateTapRecognizer];
[datesView.fromMonthYearLabel addGestureRecognizer:fromDateTapRecognizer];
[datesView.fromDayLabel addGestureRecognizer:fromDateTapRecognizer];
按钮操作
[datesView.fromDateButton addTarget:self action:@selector(tapOnfromDate) forControlEvents:UIControlEventTouchUpInside];
UIView 界面
【问题讨论】:
-
你能把你的xib文件传给我,我可以试试,因为我创建的工作正常,没有任何问题。在这里你可以通过 mshauket.developer@gmail.com
-
datesView 是你的 mainUIView 吗?
标签: ios swift uiview uibutton xib