问题
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
回答1:
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.
回答2:
Are you using simulators?
Are you sure that each iPhone have the same iOS?
If iPhone5 have iOS < 10 then try using:
private func setupViews() {
self.layer.mask = leftPhotoArc
}
来源:https://stackoverflow.com/questions/40614570/cashapelayer-circle-not-showing-on-iphone-6-but-its-working-on-iphone-5-with-th