实现效果如下:

实现代码如下:

 @interface ViewController ()<UIViewControllerTransitioningDelegate>

 {

     UILabel *optionLabel;   //显示选中值得label

     BOOL isPresentingOrDismissingOption;

     UIView *buildingOptionView;  //选择的视图

 }

 @end

 @implementation ViewController

 - (void)viewDidLoad {

     [super viewDidLoad];

     self.view.backgroundColor = [UIColor greenColor];

     buildingOptionView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];

     [self.view addSubview:buildingOptionView];

     buildingOptionView.backgroundColor = [UIColor redColor];

     buildingOptionView.layer.cornerRadius = ;

     buildingOptionView.clipsToBounds = YES;

     UIGestureRecognizer *tapOnBuildingOpetionView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnBuildingOpetionView:)];

     [buildingOptionView addGestureRecognizer:tapOnBuildingOpetionView];

     optionLabel = [[UILabel alloc] initWithFrame:CGRectMake(, , buildingOptionView.width - , )];

     optionLabel.text = @"第一教学楼";

     [buildingOptionView addSubview:optionLabel];

     optionLabel.textColor = [UIColor blackColor];

     UIImageView *arrowImageView = [[UIImageView alloc] initWithFrame:CGRectMake(optionLabel.right + ,optionLabel.top + ,,)];

     arrowImageView.image = [UIImage imageNamed:@"classroom_arrow_icon"];

     [buildingOptionView addSubview:arrowImageView];

 }

 //手势触发方法

 - (void)tapOnBuildingOpetionView:(UITapGestureRecognizer *)tap{

     NSLog(@"列表选择");

  //弹出选择列表

     OptionTableView *optionView = [[OptionTableView alloc]initWithFrame:CGRectMake(buildingOptionView.left + ,buildingOptionView.bottom + ,,) style:UITableViewStylePlain];

     optionView.buildingsArray = @[@"第一教学楼", @"第二教学楼", @"第三教学楼", @"第四教学楼", @"第五教学楼", @"第六教学楼", @"第七教学楼", @"第八教学楼"];

     [self.view addSubview:optionView];

     //block的实现,给label赋值

     [optionView setDismissOnBuilding:^(NSString *selectedBuilding) {

         optionLabel.text = selectedBuilding;

     }];

 }

OptionTableView的实现代码如下:

 #import <UIKit/UIKit.h>

 @interface OptionTableView : UITableView<UITableViewDataSource,UITableViewDelegate>

 @property (nonatomic, strong) NSArray *buildingsArray;
@property (nonatomic, copy) void (^dismissOnBuilding)(NSString *building); @end
 static NSString *const buildingOptionCellId = @"Cell";

 @interface OptionTableView ()

 @end
@implementation OptionTableView - (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{ self = [super initWithFrame:frame style:style];
if (self) { self.dataSource = self;
self.delegate = self; [self registerClass:[UITableViewCell class] forCellReuseIdentifier:buildingOptionCellId];
self.backgroundColor = [UIColor blueColor]; }
return self; } #pragma mark - Table view dataSource //行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{ return self.buildingsArray.count; } //创建单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:buildingOptionCellId forIndexPath:indexPath];
cell.textLabel.text = self.buildingsArray[indexPath.row];
return cell; } #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //block实现选中的值的传递 if (self.dismissOnBuilding) {
self.dismissOnBuilding(self.buildingsArray[indexPath.row]);
} //当选择完毕表视图收起
self.frame = CGRectZero;
}

写的不好,有更好的方法,欢迎大家告诉我,谢谢!!!

最新文章

  1. 窥探Swift之类的继承与类的访问权限
  2. Chapter 2: Design the user experience
  3. AJAX案例一:发送POST请求
  4. bootstrap-列表组
  5. iptables基本操作
  6. openssl ans.1编码规则分析及证书密钥编码方式
  7. spring管理hibernate4 transaction getCurrentSession为什么报错?
  8. Access2007中如何运行SQL执行SQl语句
  9. CRM2011 concurrency问题及解决方案
  10. CodeForces 632D Longest Subsequence
  11. Chapter 1 First Sight——18
  12. 海量日志采集系统flume架构与原理
  13. XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Saratov
  14. jquery延迟加载(懒加载)插件
  15. 【Python】进程3
  16. ES5之defineProperty
  17. How to use transparent PNG icons with Delphi ImageList
  18. C#获取相对路径[转]
  19. 从 “x is null 和 x == null” 的区别看 C# 7 模式匹配中常量和 null 的匹配
  20. Python3 异常与断言

热门文章

  1. js 数组中如何删除字典
  2. [USACO]骑马修栅栏 Riding the Fences
  3. bzoj 4319: cerc2008 Suffix reconstruction 贪心
  4. 在默认使用apache中央仓库时, 报错 protocol_version
  5. yii中异步验证和自定义方法验证
  6. Airflow 配置celery+rabbitmq和celery+redis
  7. 01.Flink笔记-编译、部署
  8. imu 返回的数据
  9. Vue插槽详解
  10. Java核心复习——J.U.C LinkedBlockingQueue源码分析