Ios 使用偏移和填充管理VSTack中的重叠元素

Ios 使用偏移和填充管理VSTack中的重叠元素,ios,swiftui,vstack,Ios,Swiftui,Vstack,我使用日历应用程序来管理每日约会。我使用一个惰性网格显示一天中活动协作者的一列。约会从核心数据加载到这些列中。约会正在进行中。我用y偏移和底部填充来定位它们。您可以在我加入的日历捕获中看到结果 在我有重叠的约会之前,它一直运作良好。只要约会的结束时间不超过或等于下一次约会的结束时间,就没有问题 我的列生成方法: Group { if let appointments = columnViewModel.columnCollab.todaySortedAppointments(fo

我使用日历应用程序来管理每日约会。我使用一个惰性网格显示一天中活动协作者的一列。约会从核心数据加载到这些列中。约会正在进行中。我用y偏移和底部填充来定位它们。您可以在我加入的日历捕获中看到结果

在我有重叠的约会之前,它一直运作良好。只要约会的结束时间不超过或等于下一次约会的结束时间,就没有问题

我的列生成方法:

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, 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?.endDate == item.endDate {
        return 0
    } else {
        var padding = ((CGFloat(appointmentDuration) * Constants.hourHeight)/60)
        return padding
    }
}
使用这些偏移和填充方法,如果存在重叠,则下一个约会将向下移动,重叠的约会将不可见。如何继续避免这种位移并保持所有预约可见