SCTiledImage
适用于 iOS 的瓦片图像视图:以类似于 GoogleMaps 的方式显示具有多级缩放/瓦片的图像。
这允许以高分辨率加载非常大的图像,并且在用户缩放或滚动时,将加载更多的细节。
图像必须切割成多个缩放级别的瓦片。
级别 0 是最高分辨率级别(当用户滚动到最大时),下一个级别的每个瓦片由较高级别 2x2 的瓦片组成(例如,4 个级别 0 的瓦片将组成 1 个级别 1 的瓦片)。
安装
SCTiledImage 通过 CocoaPods 提供,要安装它,只需将以下行添加到您的 Podfile 中
pod "SCTiledImage"
特性
SCTiledImage 支持以下功能
- 在UIScrollView的子类中以多级缩放瓦片显示大型图像
- 双击或双指点击图像缩放
- 自定义瓦片大小(常见大小为 256 x 256)和缩放级别数量
- 图像可以显示 90,180 或 -90 度的旋转
- 图像的懒加载(例如,从网络或本地磁盘),带有内存缓存
- 在瓦片加载时显示背景图像(低分辨率)
- 当用户缩放或滚动时,委托回调
示例
您可以通过下载此仓库并构建示例应用程序来查看示例(原始图像大小为 9112 x 4677 = 约等于 42 兆像素)
用法
- 实现一个
SCTiledImageScrollView
,在代码或 Interface Builder 中:这将是要显示图像的视图 - 实例化一个实现
SCTiledImageViewDataSource
协议的对象,并将它通过.set(dataSource:)
方法传递给您的SCTiledImageScrollView
实例 - 可选地,您可以设置一个
SCTiledImageScrollViewDelegate
到SCTiledImageScrollView
实例,以便在用户滚动或缩放时通知您
参照示例查看更多实现细节,以及“HoiAn”文件夹内的瓦片示例。
数据源
SCTiledImageViewDataSource
协议需要实现以下内容
weak var delegate: SCTiledImageViewDataSourceDelegate?
// delegate to call once tile images have been loaded (from network, local disk...)
let imageSize: CGSize
// size of the full resolution image
let tileSize: CGSize
// size of the tiles
let zoomLevels: Int
// number of zoom levels
func requestTiles(_ tiles: [SCTile])
// called by the SCTiledImageScrollView when some tiles are need, this function must retrieve these tiles (SCTile = row, column, level) and then call the delegate once a tile is ready
func requestBackgroundImage(completionHandler: @escaping (UIImage?) -> ())
// called by the SCTiledImageScrollView, used to return the optional background image to display when tiles are loading (low resolution version of the full image)
func getCachedImage(for tile: SCTile) -> UIImage?
// if images can be retrieve synchronously (because already cached) then this function can return them directly to improve rendering speed
// in this case, it will replace requestTiles(_ tiles: [SCTile])
// if not, return nil and requestTiles(_ tiles: [SCTile]) will be used
许可
版权所有 2016-2018 Siclo Mobile
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://apache.ac.cn/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.