LocationPickerView 1.2.0

LocationPickerView 1.2.0

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最新版本2014年12月

Chris Constable 维护。




  • 作者
  • Christopher Constable

MKMapView + UITableView + 平滑滚动。为在 iOS 上构建交互式位置选择器提供框架。

此视图在需要显示可滚动、可选择的位置以及它们在地图上的位置时非常有用。可以轻松添加搜索栏以进行搜索或过滤。

安装

手动安装

LocationPickerView 文件夹拖放到您的应用程序中。

使用

在您想要使用位置选择器的视图控制器中,将以下行添加到 viewDidLoad

LocationPickerView *locationPickerView = [[LocationPickerView alloc] initWithFrame:self.view.bounds];
locationPickerView.tableViewDataSource = self;
locationPickerView.tableViewDelegate = self;
[self.view addSubview:self.locationPickerView];

或者,您可以在 Storyboard 中设置 LocationPickerView。只需设置视图的类为 LocationPickerView

并且确保连接 table view 的代理和数据源。

高级使用

如果您想要更复杂,可以指定更多的选项

// Create the location picker
LocationPickerView *locationPickerView = [[LocationPickerView alloc] initWithFrame:self.view.bounds];
locationPickerView.tableViewDataSource = self;
locationPickerView.tableViewDelegate = self;

// Optional parameters
locationPickerView.delegate = self;
locationPickerView.shouldCreateHideMapButton = YES;
locationPickerView.pullToExpandMapEnabled = YES;
locationPickerView.defaultMapHeight = 190.0;
locationPickerView.parallaxScrollFactor = 0.4; // little slower than normal.
locationPickerView.backgroundViewColor = [UIColor yellowColor]; //set color to the tableView background without the map

// Optional setup
self.locationPickerView.mapViewDidLoadBlock = ^(LocationPickerView *locationPicker) {
    locationPicker.mapView.mapType = MKMapTypeStandard;
};
self.locationPickerView.tableViewDidLoadBlock = ^(LocationPickerView *locationPicker) {
    locationPicker.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
};

[self.view addSubview:self.locationPickerView];

特别有用的是 delegate 属性,它允许您知道何时发生重要的事情(例如,地图视图即将全屏展开)。

注意:不要设置 table view 的 backgroundColor 属性。请对单元格或 LocationPickerView 进行着色。

功能愿望列表

  • 添加与 table view 同步的地图标注。
  • 添加一些基本的搜索功能。
  • 添加更多的地图控件(缩放、追踪用户位置等)。

已知问题

  • 目前,使用动画取消选择单元格看起来不太好。您需要自己进行动画,但嘿,您可以让它变得很酷!

贡献

  1. 分支
  2. 代码
  3. 评论 :)

许可证

MIT 许可证 版权所有 © 2013 Christopher Constable