Gezinme öğesine yeni arama yolu ekleme konusunda bir sorun yaşıyorum.Broken UISearchBar animasyonu navigationItem'e gömülü
Aşağıdaki resimde de gördüğünüz gibi, birbiri ardına iki UIViewControler var ve her ikisi de arama çubuğuna sahip. Sorun, arama çubuğu ilk görüntü denetleyicide göründüğünde çirkin olan, ancak ikincisindeki değil, çirkin olan animasyon. Arama çubuğu tarafından işgal edilen alan ekranda kalır ve aniden kaybolur.
kod çok temel (projede başka değişiklik yapılmıştır) olduğu:
(C# öncelikle yazmak, bu nedenle bu kodda hata olabilir.)
ViewController.swift:
import UIKit
class ViewController: UITableViewController, UISearchResultsUpdating {
override func loadView() {
super.loadView()
definesPresentationContext = true;
navigationController?.navigationBar.prefersLargeTitles = true;
navigationItem.largeTitleDisplayMode = .automatic;
navigationItem.title = "VC"
tableView.insetsContentViewsToSafeArea = true;
tableView.dataSource = self;
refreshControl = UIRefreshControl();
refreshControl?.addTarget(self, action: #selector(ViewController.handleRefresh(_:)), for: UIControlEvents.valueChanged)
tableView.refreshControl = refreshControl;
let stvc = UITableViewController();
stvc.tableView.dataSource = self;
let sc = UISearchController(searchResultsController: stvc);
sc.searchResultsUpdater = self;
navigationItem.searchController = sc;
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "cell1");
if (cell == nil) {
cell = UITableViewCell(style: .default, reuseIdentifier: "cell1");
}
cell?.textLabel?.text = "cell " + String(indexPath.row);
return cell!;
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 20;
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vc = ViewController();
navigationController?.pushViewController(vc, animated: true);
}
@objc func handleRefresh(_ refreshControl: UIRefreshControl) {
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2), execute: {
refreshControl.endRefreshing();
})
}
func updateSearchResults(for searchController: UISearchController) {
}
}
AppDelegate.swift:
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds);
window?.rootViewController = UINavigationController(rootViewController: ViewController());
window?.makeKeyAndVisible();
UINavigationBar.appearance().barTintColor = UIColor.red;
return true
}
}
Fikirler?
Aygıtta kontrol edin. Simülatör sorunu olabilir. ViewDidLoad() 'ile deneyin (loadView()) – Krunal
Nope yerine, cihazda aynıdır. – BartoszCichecki
Ve viewDidLoad aynı sonucu veriyor. – BartoszCichecki