FlyoverKit
允许您在MKMapView
上只需零努力即可展示惊人的360°飞行视图,同时保持完整的配置选项。 FlyoverKit
构建了STLocationRequest的核心,这使您可以通过3D 360°飞行视图地图请求用户位置服务。
示例
示例应用程序是查看FlyoverKit
如何工作的绝佳方式。您将了解可用的配置选项及其如何影响飞行行为。只需打开FlyoverKit.xcodeproj
并运行FlyoverKit-Example
计划,请记住,SatelliteFlyover
和HybridFlyover
仅在真实iOS设备上工作。
安装
CocoaPods
FlyoverKit通过CocoaPods提供。要安装它,请将以下行添加到您的Podfile中
pod 'FlyoverKit'
Carthage
Carthage 是一个去中心化的依赖管理器,它会为您构建依赖项并为您提供二进制框架。
要使用 Carthage 将 FlyoverKit 集成到您的 Xcode 项目中,请在您的 Cartfile
中指定它。
github "SvenTiigi/FlyoverKit"
运行 carthage update --platform iOS
来构建框架,并将构建的 FlyoverKit.framework
拖入您的 Xcode 项目。
在您的应用程序目标的“构建阶段”设置选项卡中,点击“+”图标,选择“新运行脚本阶段”,并添加前述 Carthage 开始步骤 4,5 和 6 中的框架路径。
手动
如果您不希望使用上述任何依赖管理器,您可以将 FlyoverKit 手动集成到您的项目中。只需将 源代码
文件夹拖入您的 Xcode 项目中即可。
用法
FlyoverKit
可以以三种不同的方式实现。请根据您实现的类型选择最合适的类型。请参阅 高级部分 以配置 FlyoverKit
以满足您的需求。
FlyoverCamera
如果您已经在您的 Controller
中有 MKMapView
,并且想要向该 MapView 添加飞越功能,只需使用 FlyoverCamera
。
import FlyoverKit
// Initialize the FlyoverCamera with an already existing MKMapView
let flyoverCamera = FlyoverCamera(mapView: self.mapView)
// Initialize a location via CLLocationCoordinate2D
let eiffelTower = CLLocationCoordinate2D(latitude: 48.858370, longitude: 2.294481)
// Start flyover
flyoverCamera.start(flyover: eiffelTower)
FlyoverMapView
如果您希望显示一个预先配置为在给定位置执行飞越功能的 MapView,您应使用 FlyoverMapView
。
import FlyoverKit
// Initialize the FlyoverMapView
let flyoverMapView = FlyoverMapView()
// Initialize a location via CLLocation
let eiffelTower = CLLocation(latitude: 48.858370, longitude: 2.294481)
// Start flyover
flyoverMapView.start(flyover: eiffelTower)
FlyoverMapViewController
如果您希望显示一个包含嵌入式 FlyoverMapView
的 UIViewController
以在特定位置执行飞越,那么 FlyoverMapViewController
可以为您提供帮助。
import FlyoverKit
// Initialize a location via FlyoverAwesomePlace
let eiffelTower = FlyoverAwesomePlace.parisEiffelTower
// Initialize the FlyoverMapViewController with a Flyover object
let controller = FlyoverMapViewController(flyover: eiffelTower)
// Present controller
self.present(controller, animated: true)
高级
FlyoverKit
由三个主要组件组成。 Flyover
协议、FlyoverCamera
和 FlyoverMapView
。
Flyover 协议
flyover
协议指定了一个具有 CLLocationCoordinate2D
属性的类型。它用于对给定坐标进行飞越。
public protocol Flyover {
var coordinate: CLLocationCoordinate2D { get }
}
FlyoverKit
已经将这些协议的实现应用于各种 MapKit 和 CoreLocation 类型,如 CLLocationCoordinate2D
、CLLocation
、MKMapPoint
、MKMapItem
、MKCoordinateRegion
以及许多 其他 类型。
您可以将 Flyover
协议应用于自己的模型,以便用于飞越。
struct Address {
var name: String
var coordinate: CLLocationCoordinate2D
}
extension Address: Flyover {}
运算符
为了比较两个 Flyover
类型,您可以使用以下两个运算符。
等价运算符 (==)
self.flyover1 == self.flyover2
通过比较纬度和经度来检查两个给定的 Flyover 类型是否完全相同。
四舍五入等价运算符(~~)
self.flyover1 ~~ self.flyover2
通过比较四舍五入后的纬度和经度,检查两个给定的飞越类型是否几乎相同。
FlyoverAwesomePlace
FlyoverAwesomePlace
是一个符合 Flyover
协议的枚举,具有如 纽约自由女神像
、Googleplex
、悉尼歌剧院
等令人惊叹的位置和地标,还有很多更多。您可以在自己的实现中使用它们,或者在 FlyoverKitExample
应用程序中探索不同的位置。
FlyoverCamera
负责操作 MKMapView
相机,并使用 UIViewPropertyAnimator 执行 360° 飞越动画。
为了初始化一个 FlyoverCamera
对象,您需要传递一个引用(将弱存储)的 MKMapView
对象以及一个 FlyoverCamera.Configuration
对象。
// Initialize FlyoverCamera configuration
let configuration = FlyoverCamera.Configuration(
duration: 4.0,
altitude: 600.0,
pitch: 45.0,
headingStep: 20.0
)
// Initialize FlyoverCamera
let camera = FlyoverCamera(
mapView: mapView,
configuration: configuration
)
// Start Flyover
camera.start(flyover: location)
配置
FlyoverCamera.Configuration
结构体包含了所有特定的飞越配置值。设置属性以得到所需的飞越外观和感觉。
配置 | 描述 |
---|---|
duration | 飞越动画的持续时间 |
altitude | 海拔高度,以米为单位 |
pitch | 相机的观察角度,以度为单位 |
headingStep | 每次飞越迭代中添加到 MapViewCamera 航向的度数方向步长 |
regionChangeAnimation | 当开始飞越且 MapCamera 需要更改区域时,应该应用的区域更改动画。默认值总是 .none ,立即显示地点。如果您希望区域更改通过动画执行,则可以设置为 .animated(duration: 1.5, curve: .easeIn) |
来自 TechTopia 的 MKMapCamera
的优秀可视化
配置主题
如果您不想自己设置属性,可以使用预配置的配置主题。目前有四个主题可供选择
主题 | 描述 |
---|---|
默认 | 默认飞跃配置,针对默认飞跃使用进行配置 |
低空飞行 | 低空飞跃配置,高度低、俯仰角大。模拟低空直升机的观察角度 |
远方 | 高度高、俯仰角正常的配置,导致观察角度离得很远 |
头晕 | 头晕的配置 |
宇航员视角 | 宇航员的视角 |
此外,您可以使用给定的 Theme
初始化一个 FlyoverCamera
。
// Initialize FlyoverCamera
let camera = FlyoverCamera(
mapView: mapView,
configuration: .default
)
更多主题即将推出...
FlyoverMapView
FlyoverMapView
是一个预配置的 MKMapView
,带有嵌入式的 FlyoverCamera
。FlyoverMapView
提供了各种便利函数,例如使用 MKAnnotation
对象开始飞跃或设置支持的飞跃 MapType
。
// Initialize with default configuration theme and standard MapType
let flyoverMapView = FlyoverMapView()
// Or initialize by setting a different theme and the satelliteFlyover MapType
let flyoverMapView = FlyoverMapView(configuration: .farAway, mapType: .satelliteFlyover)
MapType
FlyoverMapView.MapType
指定了三个支持的 MKMapType
。
MapType | 描述 |
---|---|
标准 | 显示所有道路位置和3D建筑的街道地图 |
卫星飞跃 | 带有道路和道路名称信息的区域卫星图像之上层 |
混合飞跃 | 带有可用飞跃数据的混合卫星图像 |
FlyoverMapViewController
FlyoverMapViewController
是一个简单直观的方法来展示带有嵌入 FlyoverMapView
的 UIViewController
。如果您只想在一个指定的 Flyover
类型上显示 360° 飞跃,可以使用它。
// Initialize a location
let eiffelTower = CLLocationCoordinate2DMake(48.858370, 2.294481)
// Initialize the FlyoverMapViewController with a Flyover object
let controller = FlyoverMapViewController(flyover: eiffelTower)
// Present controller
self.present(controller, animated: true)
此外,您可以使用自己的 Configuration
或 Configuration.Theme
以及 MapType
初始化 FlyoverMapViewController
。
// Initialize a location
let eiffelTower = CLLocationCoordinate2DMake(48.858370, 2.294481)
// Initialize a Configuration
let configuration = FlyoverCamera.Configuration(
duration: 4.0,
altitude: 600.0,
pitch: 45.0,
headingStep: 20.0
)
// Initialize the FlyoverMapViewController
let controller = FlyoverMapViewController(
flyover: eiffelTower,
configuration: configuration,
mapType: .satelliteFlyover
)
// Present controller
self.present(controller, animated: true)
贡献力量
欢迎贡献力量
许可证
FlyoverKit
Copyright (c) 2019 Sven Tiigi <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.