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/

相关文章:

swift - 防止 NSURLSession 默认 HTTP header

ios - Swift:在 removeFromSuperview() 时崩溃

iOS 11.2.1 Xcode 9.2 BoringSSL SSL_ERROR_ZERO_RETURN(6)

xcode - 如何查看 C++ 变量的类型?

ios - 如何在 swift 中以编程方式实现具有多个原型(prototype)单元格的 UITableViewController

ios - 是否可以通过 Springboard 调整在 SBApplication 中设置 userInfo?

ios - 在不同大小的按钮上使用 StackView

iphone - 奇怪的架构,没有 appDelegate 类的应用程序。 (AVCam 源链接)

ios - 如何设置 iPhone UIView z 索引?

ios - GCM 库错误 : Integration GCM in iOS Swift