ios - 在圆圈上显示时间戳

标签 ios swift math geometry

我想使用 swift 在圆圈上显示时间戳之间的特定时间段。 (cfr截图)

enter image description here

我有这段代码显示 12:00 到 18:00 之间的时间

let π:CGFloat = CGFloat(M_PI) 
let center = CGPoint(x: bounds.width/2, y: bounds.height/2)
let radius: CGFloat = max(bounds.width,bounds.height)
let arcWidth: CGFloat = 5

let startAngle2: CGFloat = 3 * π / 2
let endAngle2: CGFloat = π / 2

 let path2 = UIBezierPath(arcCenter: center, radius: radius/2 - arcWidth / 2, startAngle: startAngle2, endAngle: endAngle2, clockwise: true)
 path2.lineWidth = arcWidth
 strokeColer2.setStroke()
 path2.stroke()

我现在需要知道的是一个函数或计算,可以给出开始和结束角度。如果有人有任何建议,请告诉我!

最佳答案

它只是线性的,12 小时 = 2π 弧度,或 1 小时 = π/6。数学惯例是逆时针方向,3 点钟 = 0 角。因此 12/0 = π/2, 3 = 0, 6 = -π/2, 9 = -π (or +π), 所以

角度 = (3 - 小时 % 12) * π/6

更新

OP 要求提供小时:分钟示例。我添加了类型。

let integerHours = 17
let minutes = 12
var fractionalHours = CGFloat(integerHours) + CGFloat(minutes) / 60
fractionalHours = fmod(fractionalHours, 12)
let angle = (3 - fractionalHours) * CGFloat(M_PI) / 6

关于ios - 在圆圈上显示时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34196113/

相关文章:

ios - SpriteKit - SKCameraNode 视差效果?

swift - 下铸 Nib uitableviewcell

C - 如何实现 Set 数据结构?

ios - 使用 NSMutableParagraphStyle 会导致表情符号出现问题

iOS7 崩溃 - [__NSPlaceholderDictionary initWithObjects

iphone - iOS5 通知下拉菜单 : is there a way to know when the user presses the clear button on my apps notification on the iPhone?

ios - 嵌套违规。类型最多嵌套 1 层深

ios - Realm <List> 已填充但只有一个对象

python - 快速查找 2 的幂中的数字

javascript - 如何在javascript中找到11的幂或x是幂n?