【发布时间】:2015-10-28 16:41:26
【问题描述】:
我在主视图中有表格。接下来,我将视图添加到高度为 100 点的上表视图,然后我的第一行高度为 100 点。接下来我检查 scrollView contentOffset 以重新计算我添加的视图的位置。当我很好地滚动表格视图时,我的视图与表格视图中的第一个单元格重复位置。
但我的问题是: 当我想从我的视图(视图中的手指)滚动并向下滚动时,表格视图与我的手势没有交互。是的,这很正常。如果我将用户交互设置为 NO,一切正常。但是我在这个视图中有一些按钮,当我禁用用户交互时,我不能在这个视图中对我的子视图进行操作。
如何在没有用户交互或其他方法的情况下同时/一起滚动和点击。谢谢。
所有代码:
#import "ViewController.h"
@interface ViewController () <UITableViewDataSource, UITableViewDelegate>
{
UIView *someView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
tableView.dataSource = self;
tableView.delegate = self;
[self.view addSubview:tableView];
someView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)];
someView.backgroundColor = [UIColor redColor];
[self.view addSubview:someView];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 10;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
if (indexPath.row == 0) return 100;
else return 44;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
if (indexPath.row == 0) cell.backgroundColor = [UIColor greenColor];
}
return cell;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
someView.center = CGPointMake(someView.center.x, -scrollView.contentOffset.y+50);
}
【问题讨论】:
-
在 tableview 或 uiview 上点击手势会使按钮无法响应早期点击事件
标签: ios objective-c uitableview uiview uiscrollview