cornerRadius停止在Swift 2.3/iOS 10/Xcode 8中工作 [英] cornerRadius stopped working in Swift 2.3 / iOS 10 / Xcode 8

查看:75
本文介绍了cornerRadius停止在Swift 2.3/iOS 10/Xcode 8中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一UIView中的UIViewUIImageView上分别设置了cornerRadius.我正在使用RockProfileView.frame.size.height / 2计算拐角半径,但是UIView在iOS 10中停止显示.

I have a cornerRadius set on a UIView and a UIImageView inside the same UIView. I am calculating the corner radius with RockProfileView.frame.size.height / 2 but the UIView stopped showing in iOS 10.

进一步检查后,我发现RockProfileView.frame.size.height / 2的值是1000.0,而宽度和高度约束设置为64.0

After further checking i found the value of RockProfileView.frame.size.height / 2 is coming out to be 1000.0 while the width and height constraint is set to 64.0

当我将RockProfileView.layer.cornerRadius = 32硬编码为64/2时,它可以正常工作.

When I hardcoded the RockProfileView.layer.cornerRadius = 32 to 64/2 it works just fine.

可能是什么问题?

完整代码:

    RockProfileView.layer.cornerRadius = RockProfileView.frame.size.height / 2
    RockProfileView.clipsToBounds = true
    RockProgressView.layer.masksToBounds = true

推荐答案

罗布(Rob)回答,我已经将代码从viewDidLoad移到了viewDidAppear,问题已得到解决.

As answered by Rob, I've moved the code from viewDidLoad to viewDidAppear and the problem is fixed.

或 在viewDidLoad中的代码之前添加self.view.layoutIfNeeded()也可以解决此问题.

OR Adding self.view.layoutIfNeeded() before your code in viewDidLoad also solves the issue.

对于UITableViewCell,在更新拐角半径之前在内部awakeFromNib中添加[self layoutIfNeeded];应该可以解决所有问题.

In case of UITableViewCell, Inside awakeFromNib add [self layoutIfNeeded]; before updating the corner radius should solve all the issues.

这篇关于cornerRadius停止在Swift 2.3/iOS 10/Xcode 8中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆