2016-11-15 9 views
0

同じコードでiPhone 5に取り組んでいない:CAShapeLayer円はiPhone 6に示すが、その私はこのようなカスタム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") 
} 
} 

を、カスタム・コレクション・ビューでそれを初期化セル:

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

+0

円が必要な場合は、 'UIBezierPath(arcCenter:...)'ではなく 'UIBezierPath(ovalIn:rect)'を使用してください。 – ovejka

+0

いいえ、私はちょうど私のポストの下に写真を見ることができる、すべての楕円形ではなく、その赤い円のパスが必要です、iphone5は、私はip6上でしたいと思っているもの(唯一の赤い形)ですが、それdoesnt仕事 –

+0

あなたの設定( 'leftPhotoArc.fillColor = nil')には赤い形だけがあり、塗りつぶされません。 – ovejka

答えて

0

てみ交換開始と終了角度:

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

それはあなたが時計回りに0から2πまで移動し、合理的な原因です。

0

シミュレータを使用していますか?
各iPhoneに同じiOSがインストールされていますか? iPhone5のはiOSの< 10がある場合
その後、使ってみてください:このような

private func setupViews() { 
    self.layer.mask = leftPhotoArc 
} 
+0

うん、私はシミュレータ10.1を使用していますが、まだ何も –

関連する問題