2017-05-30 32 views
0

我有程序创建这样一个UIView:分割的圆形的UIView到5条相等角件

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) 

我需要添加(再次编程)5子视图此UIView的。 我努力寻找subViews的锚点的坐标。

思考成度,我圈出来的superView必须分成72°,每个相等的部分,边界的坐标必须是我的子视图的锚点。

事情是这样的: enter image description here

+1

见https://stackoverflow.com/questions/839899/how-do-i用于计算给定角度的圆上位置的圆周上的点。 – 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是中心坐标,您将使用-360/n而不是-72来表示圆上不同数量的位置。 – Gerriet

+0

一个愚蠢的问题:半径这将是我的superView周长? – Alex