0

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

klapinski
  • 151
  • 1
  • 8
  • If you need a circle just use `UIBezierPath(ovalIn: rect)` instead of `UIBezierPath(arcCenter:...)`. – ovejka Nov 15 '16 at 16:59
  • nope, i only need that red circle path without fill, not all oval shape, you can see photos at the bottom of my post, iphone5 is the thing (only red shape) i'd like to make on ip6 but it doesnt work – klapinski Nov 15 '16 at 17:22
  • With your setup (`leftPhotoArc.fillColor = nil`) you will have only the red shape, without fill. – ovejka Nov 15 '16 at 17:31
  • yes, i need only that circle path because i need it to be animatable (without yellow background color) but that's not the point, its working fine on ip5 simulator, so why it doesn't on ip6 simulator – klapinski Nov 15 '16 at 17:57
  • Ok, now I got it. It works for me if I set `clockwise: false` for the path or exchange start and end angles. Also, this answer can be useful for you: http://stackoverflow.com/a/25994222/3212863 – ovejka Nov 15 '16 at 18:10
  • i made yesterday counting animatable circle shape and it's simply changing angle with some value when clicked for ex + 1 based on strokeStart/strokeEnd and it's working very well but on ip5, there are 2 elements i'm considering: different screen size and different cell size and second might be related to non retina ip5, retina ip6 and points/pixels but it's advanced topic so i though someone could answer me here :( – klapinski Nov 15 '16 at 18:24
  • You don't manipulate with pixels and it should have nothing to do with screen size either. Just try `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. – ovejka Nov 15 '16 at 18:31
  • omg... your answer worked... god damnn, i've trying everything besides this one because i thought if its working on ip5 it should work on ip6, THANK YOU btw. how can i give you some points or something? i don't understand how stack's reputation points works yet – klapinski Nov 15 '16 at 18:58
  • Great! I left an answer (the same) below and you can accept it now. – ovejka Nov 15 '16 at 20:39

2 Answers2

0

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
}
Luca Davanzo
  • 21,000
  • 15
  • 120
  • 146
0

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.

ovejka
  • 999
  • 1
  • 16
  • 21