gpt4 book ai didi

swift - CAShapeLayer 圆圈在 iPhone 6 上不显示,但它可以使用相同的代码在 iPhone 5 上工作

转载 作者:行者123 更新时间:2023-11-30 12:54:15 25 4
gpt4 key购买 nike

我在自定义 uiview 类中使用 cashapelayer 以编程方式制作了一个简单的圆圈,如下所示:

class UserProfileCircleAnimated: UIView {

private lazy var leftPhotoArc: CAShapeLayer = {
let leftPhotoArc = CAShapeLayer()
leftPhotoArc.lineWidth = 6
leftPhotoArc.strokeColor = UIColor.rgb(red: 232, green: 72, blue: 85, alpha: 1).cgColor
leftPhotoArc.fillColor = nil
leftPhotoArc.path = UIBezierPath(arcCenter: CGPoint(x: 25, y: 25), radius: 25 , startAngle: 2 * CGFloat(M_PI), endAngle: 0, clockwise: true).cgPath
return leftPhotoArc
}()

override init(frame: CGRect) {
super.init(frame: frame)

translatesAutoresizingMaskIntoConstraints = false
backgroundColor = UIColor.yellow
setupViews()
}

private func setupViews(){
layer.addSublayer(leftPhotoArc)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

并在自定义 Collection View 单元格中初始化它:

class AllCell: UICollectionViewCell {
let userProfileCircleAnimated = UserProfileCircleAnimated()
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(userProfileCircleAnimated)
userProfileCircleAnimated.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
userProfileCircleAnimated.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
userProfileCircleAnimated.widthAnchor.constraint(equalToConstant: 50).isActive = true
userProfileCircleAnimated.heightAnchor.constraint(equalToConstant: 50).isActive = true

}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

结果是在ip5模拟器上出现,而在ip6上却没有,这是为什么呢?谢谢你! iphone 5 iphone 6

最佳答案

尝试像这样交换开始和结束角度:

leftPhotoArc.path = UIBezierPath(arcCenter: CGPoint(x: 25, y: 25), radius: 25 , startAngle: 0, endAngle: 2 * CGFloat(M_PI), clockwise: true).cgPath

这是合理的,因为你顺时针从 0 移动到 2π。

关于swift - CAShapeLayer 圆圈在 iPhone 6 上不显示,但它可以使用相同的代码在 iPhone 5 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40614570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com