diff --git a/Sources/KVKCalendar/Style.swift b/Sources/KVKCalendar/Style.swift index 02bf56b8..67371736 100644 --- a/Sources/KVKCalendar/Style.swift +++ b/Sources/KVKCalendar/Style.swift @@ -194,7 +194,9 @@ public struct TimelineStyle { public var scale: Scale? = Scale(min: 1, max: 6) public var useDefaultCorderHeader = false public var eventPreviewSize: CGSize? = CGSize(width: 150, height: 150) - + /// Takes effect when `style.event.states` does not contain `.move`. `true`: create a new event at the long press; `false`: create at the start time. + public var createEventAtTouch = false + public var allLeftOffset: CGFloat { widthTime + offsetTimeX + offsetLineLeft } @@ -889,6 +891,7 @@ extension TimelineStyle: Equatable { && compare(\.timeDividerColor) && compare(\.timeDividerFont) && compare(\.scale) + && compare(\.createEventAtTouch) } } diff --git a/Sources/KVKCalendar/Timeline+Extension.swift b/Sources/KVKCalendar/Timeline+Extension.swift index e9805b1d..4e392095 100644 --- a/Sources/KVKCalendar/Timeline+Extension.swift +++ b/Sources/KVKCalendar/Timeline+Extension.swift @@ -414,7 +414,12 @@ extension TimelineView { eventPreviewSize = getEventPreviewSize() } var point = gesture.location(in: scrollView) + if style.timeline.createEventAtTouch && !style.event.states.contains(.move) { + let offset = eventPreviewYOffset - style.timeline.offsetEvent - 6 + showChangingMinute(pointY: point.y, offset: offset) + } point.y = (point.y - eventPreviewYOffset) - style.timeline.offsetEvent - 6 + let time = movingMinuteLabel.time var newEvent = Event(ID: Event.idForNewEvent) newEvent.title = TextEvent(timeline: style.event.textForNewEvent)