gpt4 book ai didi

ios - 在圆圈上显示时间戳

转载 作者:行者123 更新时间:2023-11-28 06:53:58 24 4
gpt4 key购买 nike

我想使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com