You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CYLTabBarController is a UIKit UITabBarController subclass and works in a SwiftUI app as is: put it into SwiftUI with UIViewControllerRepresentable, and write each tab's content as a SwiftUI view in a UIHostingController. Every style (Liquid Glass, classic, FlatDesign), the plus button, Lottie and badges keep working.
Register the plus button in the SwiftUI App's init (before any tab bar controller is created). Keep a UIKit app delegate with @UIApplicationDelegateAdaptor if you need one. Do not name a UISceneDelegateClassName in Info.plist: SwiftUI creates the window and the scenes.
importCYLTabBarControllerimportSwiftUI@mainstructHealthyHomeSwiftUIApp:App{@UIApplicationDelegateAdaptor(AppDelegate.self)privatevarappDelegate@StateObjectprivatevarbridge=TabBarBridge()init(){CYLPlusButtonSubclass.register()}varbody:someScene{WindowGroup{CYLTabBarControllerView(bridge:bridge).ignoresSafeArea() // the tab bar controller handles the safe area itself 由 TabBarController 自己处理安全区域
}}}
[CN]第 2 步:用 UIViewControllerRepresentable 嵌入
[EN]Step 2: embed it with UIViewControllerRepresentable
Create the tab bar controller once, in makeUIViewController. Each tab is UINavigationController(rootViewController: UIHostingController(rootView: …)). Set the style and other properties before the view loads, as in UIKit.
A SwiftUI view has no UIViewController to reach, so an ObservableObject (TabBarBridge) keeps a weak reference to the tab bar controller and is passed to the tabs as an environment object. It only calls existing API: selecting tabs by identifier (#408), badges, push, and the plus button's touchable area (#91).
finalclassTabBarBridge:ObservableObject{weakvartabBarController:CYLTabBarController?funcselect(_identifier:String){tabBarController?.cyl_selectTabBarItem(withIdentifier:identifier)}funcshowBadge(_value:String,onTabidentifier:String){tabBarController?.cyl_viewController(withTabBarItemIdentifier:identifier)?.cyl_showBadgeValue(value,animationType:.bounce)}funcpush<Content:View>(_content:Content,title:String){guardletnavigationController=tabBarController?.selectedViewControlleras?UINavigationControllerelse{return}lethostingController=UIHostingController(rootView:content.environmentObject(self))hostingController.title=titlehostingController.hidesBottomBarWhenPushed=true // hide the tab bar 隐藏 TabBar
navigationController.pushViewController(hostingController,animated:true)}}structHomeTabView:View{@EnvironmentObjectprivatevarbridge:TabBarBridgevarbody:someView{List{Button("Show \"3\" on the second tab"){bridge.showBadge("3",onTab:"healthy")}Button("Select \"me\""){bridge.select("me")}Button("Push a SwiftUI page"){bridge.push(DetailView(),title:"Detail")}}}}
The home tab (HomeTabView): a number badge on the 2nd tab, a red dot on the 3rd, clearing them; selecting the other tabs by identifier; pushing a SwiftUI page with the tab bar hidden; a Toggle that shows the plus button's touchable area and a Slider that scales it 1–3× (only with hasPlusButton()).
The other tabs and the plus button's page are SwiftUI views; the tab titles, icons and Lottie animations are the same as in Example-Swift-03.
运行:在 Example-SwiftUI 目录执行 pod install,打开 HealthyHome.xcworkspace。Podfile 与 Example-Swift-03 相同,Bundle ID 为 com.HealthyHomeSwiftUI。
To run: pod install in Example-SwiftUI, then open HealthyHome.xcworkspace. The Podfile is the same as Example-Swift-03's; the bundle identifier is com.HealthyHomeSwiftUI.
Create it once: in makeUIViewController; recreating it in updateUIViewController would drop every tab's navigation stack. SwiftUI state reaches it through TabBarBridge.
Hiding the tab bar: set hidesBottomBarWhenPushed = true when pushing (UIKit navigation stack). SwiftUI's .toolbar(.hidden, for: .tabBar) only affects a SwiftUI TabView.
Verified (2026-11-10, iOS 26.1, iPhone 17 Pro Max simulator, Liquid Glass): Example-SwiftUI builds and runs. Top to bottom: ① badges: "3" on the second tab, a red dot on the third; ② selecting "me" by identifier; ③ a pushed SwiftUI page (the tab bar hidden, as designed); ④ the plus button's page (its child view controller is a UIHostingController). The plus button's touchable-area switch was not tested this time.
TODO (the selected plus button's title is blurry, found 2026-11-10; the mask fix of 2026-11-12 is switched off at the maintainer's request (CYL_PLUS_BUTTON_LENS_MASK_ENABLED 0), so the blur is back; see the task log of Liquid-Glass-Robustness): on Liquid Glass the real plus button lies under the platter, and the lens blurs whatever is under it, so once selected its title (and an icon lying wholly inside the platter) showed as a blurred copy under the stand-in's crisp picture ("before" below; left: selected, right: not selected). Now, while the plus button's page is selected, the real button is masked out under the lens: the whole lens area when all its content is inside it, else only the title's strip (the part of an icon above the platter stays, so there is no gap); the mask goes when another tab is selected (-[CYLPlusButton cyl_updateLiquidGlassMask]). Verified (iOS 26.1, iPhone 17 Pro simulator, Liquid Glass): the unit test testTheSelectedPlusButtonTitleIsNotBlurredUnderTheLens checks there is no mask before and after (selected in code, the test host does not build the lens's stand-in, so that step is skipped and checked in screenshots); 122 tests pass. Screenshots, top to bottom: Example-SwiftUI with the plus button selected, a crisp "Menu"; Home selected again, the plus button as before; the ObjC gallery 9.4 with a crisp selected green plus icon. The Swift example was not run this time.
DONE (2026-11-12, plus button mask cut by a drag): user prompt: "谨慎实现Implementing the mask in the existing empty hook cyl_updateLiquidGlassMask 请在合适文档中进行TODO中标注,并在代码注释中标注,该方法会导致选中plusButton后,在拖拽到其他item时,原plusbutton会被切割为两部分。之前的实现由于无法解决该问题,我才删掉了该方法的实现。除非经过完整测试,不会导致用户拖拽液态玻璃遮罩的时候导致plusButton被切割,才保留该实现。该bug复现步骤为:iOS26及以上系统,液态玻璃样式非扁平样式,存在plus button存在pluschildviewcontroller ,方法会导致选中plusButton后,在拖拽到其他item时,原plusbutton会被切割为两部分。". Context: bb180d0 added a mask in -[CYLPlusButton cyl_updateLiquidGlassMask] to fix the blurry title of a selected plus button (see the DONE row above). Risk: after selecting the plus button, dragging the Liquid Glass lens to another item keeps the plus page selected and the mask on while the lens has left, so the plus button is cut in two; the maintainer removed an earlier implementation for that reason. Repro: iOS 26+, Liquid Glass (not FlatDesign), a plus child view controller; select the plus button, drag the lens to another item. Current state: the mask is off (CYLPlusButtonLensMaskEnabled = NO, noted in the code comment), back to the behavior before the fix (the blurry title of a selected plus button is back). Requirement: turn it on only after full testing (the plus button stays whole during and after the drag). Result: the mask is off while the lens is pressed or dragged (UIKit's Liquid Glass gesture began / changed) and checked again 0.45 s after the gesture ends (-cyl_setLiquidGlassLensMaskSuspended:); the mask is on again. Verified by two UI tests, recorded on video: testDraggingTheLensAwayFromTheSelectedPlusButton (Example-SwiftUI, raised plus) and testDraggingTheLensAwayFromAFlatSelectedPlusButton (ObjC gallery 9.4, icon wholly inside the lens): the plus button stays whole during and after the drag; in the control run (suspension off) the plus button disappears while the lens is held on Find. 129 unit tests pass on iOS 26.1 and 17.5. Screenshots, top to bottom: control run while dragging (plus button gone); with the fix: selected, while dragging (whole), after the drag. iOS · iOS 26.1 simulator, iPhone 17 Pro · Xcode 27.2 (iOS SDK 27.2) · macOS 27.3 · branch feat/cross-platform-components · 2026-11-12 15:59 NZDT.