It seems KNNaviView has some subviews (KNBottomView and KNCurDirectionView) that might be maintaining strong references even after the main view is removed. Since these are internal SDK components, we can’t directly control their lifecycle.
Try this modified cleanup approach:
swiftCopydeinit {
// First clear all delegates
if let guidance = KNSDK.sharedInstance()?.sharedGuidance() {
guidance.stop()
guidance.guideStateDelegate = nil
guidance.routeGuideDelegate = nil
guidance.locationGuideDelegate = nil
}
// Clear naviView delegates before release
naviView?.stateDelegate = nil
naviView?.guideStateDelegate = nil
// Try forcing layout update before removal
naviView?.setNeedsLayout()
naviView?.layoutIfNeeded()
// Remove from superview
naviView?.removeFromSuperview()
// Release and nil out
naviView?.release()
naviView = nil
// Consider calling this only when truly done with navigation
// KNSDK.releaseInstance()
}
Since KNBottomView and KNCurDirectionView appear to be persistent, you might want to try:
Setting their frames to .zero before removal
Checking if the SDK has any specific cleanup methods for these views
Contacting Kakao SDK support as this might be an SDK issue
Also, in your naviStart function, try:
swiftCopyfunc naviStart(trip: KNTrip) {
// Clear any existing navigation view first
if let existingNaviView = naviView {
existingNaviView.stateDelegate = nil
existingNaviView.guideStateDelegate = nil
existingNaviView.removeFromSuperview()
existingNaviView.release()
}
guard let guidance = KNSDK.sharedInstance()?.sharedGuidance() else { return }
guidance.guideStateDelegate = self
guidance.routeGuideDelegate = self
guidance.locationGuideDelegate = self
let naviView = KNNaviView(guidance: guidance, trip: trip, routeOption: .recommand, avoidOption: .none.rawValue)
self.naviView = naviView
naviView.stateDelegate = self
naviView.guideStateDelegate = self
view.addSubview(naviView)
naviView.frame = view.bounds
}
If possible, try implementing viewWillDisappear:
swiftCopyoverride func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if isMovingFromParent {
if let guidance = KNSDK.sharedInstance()?.sharedGuidance() {
guidance.stop()
}
}
}
If the issue persists, it might be worth:
Filing a bug report with Kakao SDK team
Checking if there’s a newer version of the SDK that might have fixed this issue
Consider creating a separate window/root view controller for navigation to better isolate the SDK components