问题描述
我在一个日历应用上工作,它允许管理日常约会。我使用一个懒惰的网格来显示当天活跃合作者的一列。约会从核心数据加载到这些列中。约会在 vstack 中。我用 y 偏移和底部填充来定位它们。您可以在 calendar capture 我加入的日历捕获中看到结果。
它运行良好,直到我有重叠的约会。只要约会的结束时间不超过或等于下一次约会的结束时间就没有问题
我的列构建方法:
Group {
if let appointments = columnviewmodel.columnCollab.todaySortedAppointments(for: day),let dayHours = columnviewmodel.columnCollab.collabHours.first(where: {$0.dayID == day.dayOfWeek()}),dayHours.active {
// allow to receive onDrop
Color.black.opacity(0.001)
vstack(spacing: 0) {
dayBeginning(collabHours: dayHours).zIndex(1)
if appointments.count == 0 {
Spacer().zIndex(1)
} else {
ForEach(appointments,id: \.id) { item in
AppointmentView(rdv: item,viewColor: Color.green,viewHeight: appointmentHeight(appointment: item))
.offset(y: appointmentOffset(item: item,collabHours: dayHours))
.padding(.bottom,appointmentPadding(item: item,collabHours: dayHours))
}
}
Spacer(minLength: 0)
dayEnding(collabHours: dayHours).zIndex(1)
}.frame(height: Constants.dayHeight,alignment: .topLeading)
} else {
vstack {
Spacer()
}
}
}
我的偏移量、填充计算:
private func appointmentOffset(item: Appointment,collabHours: DailyHours) -> CGFloat {
let startDay = currentDay.getDateFrom(hour: collabHours.startHour,minutes: collabHours.startMinute)
let prevIoUs = columnviewmodel.columnCollab.todaySortedAppointments(for: currentDay).before(item)
var appointmentDuration = item.startDate!.getMinutesDuration(from: prevIoUs?.endDate ?? startDay)
if prevIoUs?.startDate == item.startDate {
return 0
} else {
var offset = ((CGFloat(appointmentDuration) * Constants.hourHeight)/60)
return offset
}
}
private func appointmentPadding(item: Appointment,minutes: collabHours.startMinute)
let prevIoUs = columnviewmodel.columnCollab.todaySortedAppointments(for: currentDay).before(item)
var appointmentDuration = item.startDate!.getMinutesDuration(from: prevIoUs?.endDate ?? startDay)
if prevIoUs?.endDate == item.endDate {
return 0
} else {
var padding = ((CGFloat(appointmentDuration) * Constants.hourHeight)/60)
return padding
}
}
使用这些偏移和填充方法,如果有重叠,则下一个约会向下移动并且重叠的约会不可见。如何继续避免这种转移并保持所有约会可见?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)