kam.voick kam.voick - 23 days ago 6
Swift Question

CAShapeLayer circle not showing on iPhone 6, but its working on iPhone 5 with the same code

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

Answer

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.