您可以随心所欲地创建一个 UIView,并让选择器启动它以类似于相同的感觉:
以这张照片为例:
视图可以这样制作,注意 filterView 已添加到超级视图中,因为我已将视图的 userInteractionEnabled 设置为 NO,因此用户必须在继续使用视图之前选择一个选项,但是,它是可选的,我只是指出来:
self.view.userInteractionEnabled = NO;
[self.navigationItem.rightBarButtonItem setEnabled:NO];
self.filterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)];
float X_CO = (self.view.superview.bounds.size.width - self.filterView.frame.size.width)/2;
float Y_CO = (self.view.superview.bounds.size.width - self.filterView.frame.size.height)/2;
[self.filterView setFrame:CGRectMake(X_CO, Y_CO + 75, 150, 150)];
self.filterView.backgroundColor = [UIColor whiteColor];
self.filterView.layer.borderColor = [UIColor lightGrayColor].CGColor;
self.filterView.layer.borderWidth = 1.0f;
self.filterView.layer.cornerRadius = 8.0f;
self.filterView.layer.shadowColor = [UIColor blackColor].CGColor;
self.filterView.layer.shadowOpacity = 0.5f;
self.filterView.layer.shadowOffset = CGSizeMake(0, 1);
self.filterView.layer.masksToBounds = NO;
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 50)];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.text = @"Select Filter Option:";
titleLabel.font = [UIFont fontWithName:@"Eurostile" size:13];
titleLabel.textColor = [UIColor colorWithRed:48/255 green:131/255 blue:251/255 alpha:1];
[self.filterView addSubview:titleLabel];
self.azButton = [[UIButton alloc] initWithFrame:CGRectMake(10,self.filterView.frame.origin.y/3.5,30, 30)];
[self.azButton setBackgroundColor:[UIColor whiteColor]];
[self.azButton addTarget:self action:@selector(filterButton:) forControlEvents:UIControlEventTouchUpInside];
self.azButton.layer.borderColor = [UIColor lightGrayColor].CGColor;
self.azButton.layer.cornerRadius = 15.0f;
self.azButton.layer.borderWidth = 1.0f;
[self.filterView addSubview:self.azButton];
UILabel *azLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.azButton.frame.origin.x + 40, self.azButton.frame.origin.y, 95, 30)];
azLabel.textAlignment = NSTextAlignmentLeft;
azLabel.text = @"A-Z Sort";
azLabel.textColor = [UIColor blackColor];
azLabel.font = [UIFont fontWithName:@"Eurostile" size:20];
[self.filterView addSubview:azLabel];
self.zaButton = [[UIButton alloc] initWithFrame:CGRectMake(10, self.azButton.frame.origin.y + 40,30, 30)];
[self.zaButton setBackgroundColor:[UIColor whiteColor]];
[self.zaButton addTarget:self action:@selector(filterButton:) forControlEvents:UIControlEventTouchUpInside];
self.zaButton.layer.borderColor = [UIColor lightGrayColor].CGColor;
self.zaButton.layer.cornerRadius = 15.0f;
self.zaButton.layer.borderWidth = 1.0f;
[self.filterView addSubview:self.zaButton];
UILabel *zaLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.azButton.frame.origin.x + 40, self.zaButton.frame.origin.y, 95, 30)];
zaLabel.textAlignment = NSTextAlignmentLeft;
zaLabel.text = @"Z-A Sort";
zaLabel.textColor = [UIColor blackColor];
zaLabel.font = [UIFont fontWithName:@"Eurostile" size:20];
[self.filterView addSubview:zaLabel ];
[self.view.superview addSubview:self.filterView];
您可以添加背景图像以产生弹出视图的效果。
然后在用户触摸点调用它。
只是一个例子:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
UITouch *touch = [touches anyObject];
if ([touch.view isKindOfClass: UITableView.class]) {
//your touch was in a UITableView ... do whatever you have to do
}
}
然后对 touchesEnded 做同样的事情:但是还有很多其他的方法可以做到这一点。 (即,找到确切的联系点等,但这取决于你。
正如 Duncan C 指出的那样,还有其他免费可用的框架可供使用。
当然,您总是可以在故事板或 xib 中创建它,有很多选择