ios - UIScrollView 内容插图无法移除?
问题描述
您好,我正在尝试使用 swift 创建一个侧滚动条(我需要与 IOS9 兼容,但我无法使用UIScrollview.contentInsetAdjustmentBehavior = .never
),并且在创建没有内容插入的 UIScrollView 时遇到问题。下面的代码显示了我所做的,我希望有人能指出我的一些东西。
override func viewDidLoad() {
super.viewDidLoad()
automaticallyAdjustsScrollViewInsets = false //
let someView = UIView()
someView.frame = UIScreen.main.bounds
someView.backgroundColor = .yellow
view.addSubview(someView)
// some image size calcs to keep the image in the same proportions on all devices.
let frame = view.frame
let height = frame.height * 0.35
let ratioFactor = CGFloat(8.82)
let width = height * ratioFactor
let hillsImgView = UIImageView()
let image = UIImage(named: "hills")
hillsImgView.image = image
// place imageView at the bottom of the screen
let rect = CGRect(x: 0, y: frame.height - height, width: width, height: height)
hillsImgView.frame = rect
hillsImgView.backgroundColor = .green
hillsImgView.contentMode = UIImageView.ContentMode.scaleToFill
let hillsScrollView = UIScrollView()
hillsScrollView.frame = UIScreen.main.bounds
hillsScrollView.frame.origin.x = 10 // just to see the parent views yellow bg
hillsScrollView.backgroundColor = .red
hillsScrollView.contentSize = hillsImgView.frame.size // the image is longer then the screen
hillsScrollView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0 right: 0)
hillsScrollView.contentOffset = CGPoint(x: 0, y: 0)
hillsScrollView.addSubview(hillsImgView)
someView.addSubview(hillsScrollView)
}
我可以设置 imageview x 位置来移除 SafeArea 插图,但我觉得这也不是一个很好的解决方案。
干杯 T。
解决方案
推荐阅读
- r - 使用 group_by 时不支持的类型
- java - Mongodb Query, search array elements inside document grouping by and counting each element
- maven - JaCoCo 报道缺失
- mysql - 以 1 分钟间隔更新日期和时间序列 MYSQL
- python - 如何将来自大学记分卡 API 的 JSON 数据解析为 HTML 文件?
- linux - 解释这个 bash 重定向行为
- php - 如何更改 App Engine 中的最大和最小延迟?
- javascript - 过滤数据然后显示路径的搜索框?
- c# - 调用后.net远程关闭与服务器的连接
- codeigniter - Codeigniter 按价格分页排序从第 2 页开始不起作用