我想创建一个从视图一侧滑动的菜单,因此我以编程方式创建了一个 UIView 和一个 UITableView,但是,当它出现时我无法选择视图中的单元格,这是我创建视图的代码和表格:
paintView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 160, 400)];
[paintView setBackgroundColor:[UIColor clearColor]];
tablaConfig = [[UITableView alloc]initWithFrame:CGRectMake(-160, 0, 160, 400) style:UITableViewStylePlain];
tablaConfig.delegate = self;
tablaConfig.dataSource = self;
tablaConfig.userInteractionEnabled = YES;
tablaConfig.scrollEnabled = NO;
tablaConfig.backgroundColor = [UIColor lightGrayColor];
[paintView addSubview:tablaConfig];
这是我让表格出现和消失的代码:
- (IBAction)btnTablaConfig:(id)sender {
if (selector) {
if (self.view.frame.origin.x == 0) {
//[self.view addSubview:paintView];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
CGRect rect = self.view.frame;
// Move right.
rect.origin.x += 160;
rect.size.width -= 160;
self.view.frame = rect;
[UIView commitAnimations];
selector = false;
tablaConfig.userInteractionEnabled = YES;
}
}
else {
if (self.view.frame.origin.x == 160) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5]; // if you want to slide up the view
CGRect rect = self.view.frame;
rect.origin.x -= 160;
rect.size.width += 160;
self.view.frame = rect;
[UIView commitAnimations];
selector = true;
tablaConfig.userInteractionEnabled = NO;
}
//[paintView removeFromSuperview];
}
}
希望你能帮忙
编辑:
当我使用这个时,我可以选择单元格,但是失去了滑动效果,我怎样才能同时获得?
- (IBAction)btnTablaConfig:(id)sender {
if (selector) {
[self.view addSubview:tablaConfig];
selector = false;
}
else {
[tablaConfig removeFromSuperview];
selector = true;
}