ios - 如何自动圆化弹出 View 的边缘?

标签 ios swift xcode view imageview

我正在为我正在制作的应用程序开发弹出 View 。如果您花一点时间看一下下面所附的图像,您会发现顶部边缘是圆形的,但底部边缘不是。这是因为我只圆化了 View 的边缘(它在层次结构中处于最低位置)。我无法将图像(彩色框)的边缘弄圆,因为它们是 ScrollView 中的表格。我能想到的唯一解决方案是一个非常丑陋的解决方案,我用 UIImageView 遮盖底部边缘,该 UIImageView 在弹出窗口淡入后出现。有人有更好的解决方案吗?如果是这样,我将非常感谢您的帮助。另外,我的 ScrollView 尚未起作用,因此此处未引用该解决方案(如果起作用)无论如何都应该起作用。

我的代码:

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()
        }
    }
}

我指的是图像:image

最佳答案

由于您想要舍入的 View 位于 TableView 单元格内,因此您必须注意创建的 View 仅在每个重用单元格中添加一次。

每次重用的单元格滚动到 View 中时,检查它是否有 imageView subview (使用单元格内唯一的标记是进行检查的快速方法)。如果您没有,请创建它,然后为特定行配置它,否则只需为特定行配置它...

(警告,我的语速不太流利,但思路应该很清晰)

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
}

关于ios - 如何自动圆化弹出 View 的边缘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52820966/

相关文章:

ios - 将 HKSampleQuery 结果限制为来自您自己的应用程序的输入

ios - Sprite Kit 创建倒数计时器问题

ios - 在 UIWebView Swift 中安装 subview

iphone - 如何在xcode中调用多个web服务

ios - ObjC 对象内存分析/解析 iOS 128kB 限制

ios - 连接蓝牙扫描仪后,iOS 中的默认键盘消失

ios:文本在 iPhone 5S 及更早版本(4 英寸及更小的设备)上无法正确换行

ios - 水平缩放背景彩色图像

ios - Opengles片段着色器实现效果

xcode - 更改 SearchResultsController 的顶部状态栏颜色(使用 Swift)