首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何自动为弹出视图的边缘设置圆角?

如何自动为弹出视图的边缘设置圆角?
EN

Stack Overflow用户
提问于 2018-10-16 00:25:44
回答 1查看 113关注 0票数 0

我正在为我正在制作的应用程序的弹出视图工作。如果您花一秒钟时间查看下面附加的图像,您将看到顶部边缘是圆角的,但底部边缘不是。这是因为我只对视图的边缘进行了圆角处理(它在层次结构中是最底层的)。我不能使图像(彩色方框)的边缘变圆,因为它们是滚动视图中的表格。我能想到的唯一解决方案是一个非常丑陋的解决方案,我用一个在弹出窗口淡入时出现的UIImageView来遮盖底部边缘。有人有更好的解决方案吗?如果是这样的话,我将非常感谢您的帮助。另外,我的滚动视图还不能正常工作,所以这里没有提到这一点,而且解决方案(如果可以工作)应该可以正常工作。

我的代码:

代码语言:javascript
复制
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()
        }
    }
}

我所指的图像:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-16 03:41:54

由于您想要四舍五入的视图位于表格视图单元格内,因此您必须注意在每个重用的单元格中只创建一次视图。

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

(警告,我不是很流利,但我的想法应该是清晰的)

代码语言:javascript
复制
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
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52820966

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档