ios - 如何自动圆化弹出视图的边缘?
问题描述
我正在为我正在制作的应用程序制作弹出视图。如果您花一点时间查看下面附加的图像,您会看到顶部边缘是圆形的,但底部边缘不是。这是因为我只对视图的边缘进行了四舍五入(它在层次结构中最低)。我无法将图像(彩色框)的边缘弄圆,因为它们是滚动视图中的表格。我能想到的唯一解决方案是一个非常丑陋的解决方案,我用 UIImageView 掩盖底部边缘,一旦弹出窗口消失,就会出现。有没有人有更好的解决方案?如果是这样,我将非常感谢您的帮助。此外,我的滚动视图还没有功能,所以这里没有引用,解决方案(如果功能)无论如何都应该工作。
我的代码:
allSeenPopover.layer.cornerRadius = 5
userProfile.layer.cornerRadius = 15
colorBackground.layer.cornerRadius = 15
colorBackground.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
@IBAction func loadUserProfile(_ sender: Any) {
if darken.alpha == 0 {
darken.alpha = 1
self.view.addSubview(userProfile)
userProfile.center = self.view.center
userProfile.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
userProfile.alpha = 0
UIView.animate(withDuration: 0.3) {
self.largeDropShadow.alpha = 0.3
self.userProfile.alpha = 1
self.userProfile.transform = CGAffineTransform.identity
}
}
else {
UIView.animate(withDuration: 0.2, animations: {
self.userProfile.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
self.userProfile.alpha = 0
self.darken.alpha = 0
self.largeDropShadow.alpha = 0
}) { (success:Bool) in
self.userProfile.removeFromSuperview()
}
}
}
解决方案
由于您想要四舍五入的视图位于表格视图单元格内,因此您必须注意每个重用单元格只添加一次视图。
每次重复使用的单元格滚动到视图中时,检查它是否具有 imageView 子视图(使用单元格内唯一的标签是进行该检查的快速方法)。如果您没有,请创建它,然后为特定行配置它,否则只需为特定行配置它...
(警告,我不是很快流利,但这个想法应该很清楚)
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellReuseIdentifier) as UITableViewCell!
let imageView:UIImageView = cell.viewWithTag(99) as? UIImageView
if (!imageView) {
// this code runs just once per reused cell, so setup
// imageView properties here that are row-independent
imageView = UIImageView()
imageView.tag = 99 // so we'll find this when the cell gets reused
imageView.layer.cornerRadius = 15.0
imageView.clipsToBounds = true
// any other props that are the same for all rows
imageView.frame = // your framing code here
cell.addSubview(imageView)
}
// this code runs each time a row scrolls into view
// so setup properties here that are row-dependent
imageView.image = // some function of indexPath.row
return cell
}
推荐阅读
- mysql - 将 UTF8MB4 附加字符转换回 UTF8 对应字符
- python - 将超过 1 个 arg 添加到列表 python
- unity3d - 渐变着色器 Z 仅在场景视图中战斗
- gem5 - 如何将环境变量传递给 gem5 系统调用仿真模拟?
- axios - 从封面艺术档案 (archive.org) API 中获取专辑封面会由于重定向导致 CORS 错误
- node.js - 如何更改代码以同步运行
- r - 我的轴标题括号中的上标
- dart - 讨论问题:为什么 dart 不允许在课堂上声明枚举?
- php - 我收到错误“此软件包需要 php >=7.2.5 但您的 HHVM 版本不满足该要求。” 做作曲家更新时
- cucumber - 柏树黄瓜预处理器标签在 docker 容器内不起作用