同じコードで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
円が必要な場合は、 'UIBezierPath(arcCenter:...)'ではなく 'UIBezierPath(ovalIn:rect)'を使用してください。 – ovejka
いいえ、私はちょうど私のポストの下に写真を見ることができる、すべての楕円形ではなく、その赤い円のパスが必要です、iphone5は、私はip6上でしたいと思っているもの(唯一の赤い形)ですが、それdoesnt仕事 –
あなたの設定( 'leftPhotoArc.fillColor = nil')には赤い形だけがあり、塗りつぶされません。 – ovejka