2017-05-30 2 views
0

スプリット私はUIViewのは、そのようにプログラムで作成した5つの等しい角度片に円形のUIView

forecastWeatherWheel.backgroundColor = UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.1) 
    forecastWeatherWheel.frame = CGRect(x: -(dailyWeatherContainer.frame.width + 100)/2, 
             y: self.view.bounds.height/2 - ((dailyWeatherContainer.frame.height + 100)/2), 
             width: dailyWeatherContainer.frame.width + 100, 
             height: dailyWeatherContainer.frame.height + 100) 
    forecastWeatherWheel.layer.cornerRadius = forecastWeatherWheel.bounds.size.width/2 
    forecastWeatherWheel.translatesAutoresizingMaskIntoConstraints = false 
    self.view.addSubview(forecastWeatherWheel) 

を、私はこのUIViewのに(再び、プログラム)5つのサブビューを追加する必要があります。 私は、サブビューのアンカーポイントの座標を見つけるのに苦労しています。

度を考えてみると、サークルされたスーパービューは72度に分割され、境界線の座標はサブビューのアンカーポイントでなければなりません。このような

何か:このよう enter image description here

+1

がhttps://stackoverflow.com/questions/839899/how-do-iを参照してください。 -calculate-a-point-on-a-circle-s-circumferential指定された角度の円上の位置を計算するための円周上の点。 – Gerriet

答えて

2

(トップから始まり、時計回りに行く):

let radius: Double = 100 
let cx: Double = 0 
let cy: Double = 0 
for deg in stride(from: 90, to: -269, by: -72) { 
    let a = Double(deg)*M_PI/180 
    let x = cx + radius * cos(a) 
    let y = cy + radius * sin(a) 
    print("Angle \(a): \(x), \(y)") 
} 
+0

スーパー!私は三角法のやっかいです:-Dありがとう! – Alex

+1

あなたは大歓迎です:-)明らかでない場合:cx/cyが中心座標で、サークル上の異なる位置の数に-72の代わりに-360/nを使用します。 – Gerriet

+0

愚かな質問:半径それは私のsuperViewの円周になるのだろうか? – Alex

関連する問題