【发布时间】:2014-08-27 00:31:54
【问题描述】:
我使用了NIDropDown 示例,我想创建一个小菜单,当点击时它会从右侧导航栏下拉。我也看到了其他示例,但我不想填充整个控制器,当我只填充按钮下方的空间时,这对我来说就足够了,并且使用该组件中的示例真的很容易。问题是我无法选择显示表中的任何行,除了第一行。我想这是因为桌子的其余部分在导航栏之外,对吗?我该如何解决?我可以以某种方式扩展手势识别器的区域吗?还是应该在表格中添加新的识别器?
在我的控制器中,我有这些代码行用于创建右栏按钮并显示下拉列表:
- (void)setRightBarButtonItem
{
UIButton *rightButton = [NavigationBarHelper getRightBarButtonItemForMenu];
[rightButton addTarget:self action:@selector(rightBarButtonTapped:) forControlEvents:UIControlEventTouchDown];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
}
- (void)rightBarButtonTapped:(id)sender
{
MAAppDelegate* appDelegate = (MAAppDelegate*)[[UIApplication sharedApplication] delegate];
NSArray *menuItems = [appDelegate menuItems];
NSArray *arrayOfNames = [menuItems valueForKey:@"text"];
if(dropDown == nil) {
CGFloat f = 320;
dropDown = [[NIDropDown alloc]showDropDown:sender :&f :arrayOfNames :nil :@"down"];
dropDown.delegate = nil;
[_tableView setUserInteractionEnabled:NO];
}
else {
[dropDown hideDropDown:sender];
dropDown = nil;
[_tableView setUserInteractionEnabled:YES];
}
}
这里是showDropDown 方法:
- (id)showDropDown:(UIButton *)b:(CGFloat *)height:(NSArray *)arr:(NSArray *)imgArr:(NSString *)direction {
btnSender = b;
animationDirection = direction;
self.table = (UITableView *)[super init];
if (self) {
// Initialization code
CGRect btn = b.frame;
self.list = [NSArray arrayWithArray:arr];
self.imageList = [NSArray arrayWithArray:imgArr];
if ([direction isEqualToString:@"up"]) {
self.frame = CGRectMake(btn.origin.x, btn.origin.y, btn.size.width, 0);
self.layer.shadowOffset = CGSizeMake(-5, -5);
}else if ([direction isEqualToString:@"down"]) {
self.frame = CGRectMake(btn.origin.x, btn.origin.y+btn.size.height, btn.size.width, 0);
self.layer.shadowOffset = CGSizeMake(-5, 5);
}
self.layer.masksToBounds = NO;
self.layer.shadowRadius = 5;
self.layer.shadowOpacity = 0.5;
table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 140, 0)]; //btn.size.width
table.delegate = self;
table.dataSource = self;
table.backgroundColor = kDarkGreen;
table.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
table.separatorColor = [UIColor grayColor];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
if ([direction isEqualToString:@"up"]) {
self.frame = CGRectMake(btn.origin.x, btn.origin.y-*height, btn.size.width, *height);
} else if([direction isEqualToString:@"down"]) {
self.frame = CGRectMake(btn.origin.x, btn.origin.y+btn.size.height, 140, *height); //btn.size.width
}
table.frame = CGRectMake(0, 0, 140, *height); //btn.size.width
[UIView commitAnimations];
[b.superview addSubview:self];
[self addSubview:table];
}
return self;
}
【问题讨论】:
标签: ios uitableview drop-down-menu uinavigationbar uigesturerecognizer