求助:UISearchController点击时内容提前跳转致动画异常问题
Hey folks, I'm dealing with a frustrating animation bug when using UISearchController. When I tap to activate the search bar, the content underneath it snaps up to the top of the view.safeAreaLayoutGuide before the search controller's animation completes—making the whole transition feel janky and unsmooth.
I've replicated this issue in a stripped-down test project, and you can see exactly what's happening in a demo animation.
Here's the relevant code from my project:
ViewController.swift
private lazy var text: UILabel = { let label = UILabel() label.text = "dfgh" label.translatesAutoresizingMaskIntoConstraints = false return label }() override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .white setupSearchController() setupLabel() } func setupSearchController() { let searchController = UISearchController(searchResultsController: nil) searchController.searchBar.placeholder = "Search for names and emails" navigationItem.searchController = searchController } func setupLabel() { view.addSubview(text) text.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true text.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true }
SceneDelegate.swift
guard let windowScene = (scene as? UIWindowScene) else { return } window = UIWindow(windowScene: windowScene) let vc = ViewController() let nc = UINavigationController(rootViewController: vc) window?.rootViewController = nc window?.makeKeyAndVisible()
I've also shared the full test project via a Git repo. Does anyone know how to fix this animation glitch so the content transitions smoothly alongside the search controller? Thanks a ton for any help!
内容的提问来源于stack exchange,提问作者Carlos Damião

