CAShapeLayer圈不显示在iPhone 6上,但它的工作在iPhone 5与相同的代码 [英] CAShapeLayer circle not showing on iPhone 6, but its working on iPhone 5 with the same code
本文介绍了CAShapeLayer圈不显示在iPhone 6上,但它的工作在iPhone 5与相同的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在自定义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,顺时针:true).cgPath
return leftPhotoArc
}()
override init(frame:CGRect){
super.init(frame:frame)
translatesAutoresizingMaskIntoConstraints = false
backgroundColor = UIColor.yellow
setupViews()
}
private func setupViews(){
layer.addSublayer(leftPhotoArc)
}
需要init?(coder aDecoder:NSCoder){
fatalError(init(coder :) has not been implemented )
}
}
并在自定义集合视图中初始化cell: / p>
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 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),顺时针:true).cgPath
这是合理的,因为顺时针从0到2π。
i made a simple circle programatically with cashapelayer in custom uiview class like this:
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") } }
and initialized it in custom collection view cell:
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") } }
and the result is that it appears on ip5 simulator, but not on ip6, why is that? Thank you! iphone 5 iphone 6
解决方案Try exchange start and end angle like this:
leftPhotoArc.path = UIBezierPath(arcCenter: CGPoint(x: 25, y: 25), radius: 25 , startAngle: 0, endAngle: 2 * CGFloat(M_PI), clockwise: true).cgPath
it's reasonable cause you move from 0 to 2π clockwise.
这篇关于CAShapeLayer圈不显示在iPhone 6上,但它的工作在iPhone 5与相同的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文