2015-07-10 14 views
8

UINearchs'ın bir UISearchController ile ilişkili benim UINavigationItem'in başlığında bir UISearchBar var. Geri gittiğimde, yanıp sönüyor. Bunu daha önce gören var mı?UISearchBar, neden geri giderken garip bir şekilde yanıp sönüyor?

@interface HNTileSearchViewController() <HNTileSearchResultsProtocol, SWRevealViewControllerDelegate, UISearchBarDelegate, HNSetSearchFiltersProtocol, HNKeywordResultsProtocol> 
... 
@property (nonatomic, strong) UISearchController *searchController; 
@property (nonatomic, strong) UISearchBar * searchBarTop; 
... 
@end 


@implementation HNTileSearchViewController 
... 
    - (void) customPreSetup { 
     HNKeywordResultsTableViewController * searchResultsController = [self.storyboard instantiateViewControllerWithIdentifier:HNKeywordResultsTableViewControllerStoryboardIdentifier]; 
     searchResultsController.delegate = self; 
     _searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController]; 
     _searchController.searchResultsUpdater = searchResultsController; 
     _searchController.hidesNavigationBarDuringPresentation = NO; 
     _searchController.dimsBackgroundDuringPresentation = NO; 
     _searchBarTop = _searchController.searchBar; 
     _searchBarTop.delegate = self; 
     _searchBarTop.placeholder = NSLocalizedString(@"Search heynay", nil); 
     _searchBarTop.showsCancelButton = NO; 
     _searchBarTop.showsScopeBar = NO; 
     self.navigationItem.titleView = _searchBarTop; 
     self.definesPresentationContext = YES; 
    } 

    - (void) viewDidLoad { 
     [super viewDidLoad]; 
     [self customPreSetup]; 
     ... 
    } 
.... 
@end 

cevap

4

vid of flash Ben aynı sorunu vardı ve ben iki şekilde çözülebilir:

İlk olarak, Prominent'dan için searchStyle koyabilirsiniz:

searchController.searchBar.searchBarStyle = .Prominent 

Ben Swift yazdım Bu arada, bu çözümle ilgili problem, arama simgesinin ve metnin ve yer tutucunun daha koyu bir renge sahip olmasıdır ve arka plan daha koyu bir renkse, kötü görünüyor.

buldum ikinci çözüm

şudur:

navigationController!.navigationBar.translucent=false 
navigationController!.navigationBar.barTintColor=UIColor.redColor() 

searchController.searchBar.barTintColor=UIColor.redColor() 
searchController.searchBar.searchBarStyle = .Prominent 
searchController.searchBar.translucent=false 

anahtar gezinti çubuğu ve arama çubuğu hem saydam değildir ve her ikisi de aynı renkte olduğunu olmasıdır.

Bu size

+2

sayesinde, @Omzarzi! Benim için anahtar şuydu: '_searchController.searchBar.barTintColor = [HN_APP_DELEGATE brandColor]; –

0

benim için işe yaramadı @omarzl cevabını yardımcı olur umarım ... Ama biraz geçici çözüm bulundu. Buraya bir cevap olarak gönderiyorum, belki birilerine yardım edebilir.

Çok basit ve Swift 3.0'da yazılmış. görünüm yeniden görüntülenir tekrar ne zaman

override func viewWillDisappear(_ animated: Bool) { 

    searchBars.isHidden = true 

} 
... ve görünür hale getirmek:

Yani görünümü kaybolduğunda ben sadece bunu gizlemek, UISearchBar garip flaş önlemek için

override func viewDidAppear(_ animated: Bool) { 

    self.searchBars.isHidden = false 

} 

Bunun gerçekten bir çözüm değil, bir "geçici çözüm" olduğunu biliyorum. Ancak, bu çalışır ve sizin app buggy UISearBar sahip olmanın biraz daha güzel hale getirir.

3

Bana göre, searchBar kurulumu sırasında backgroundImage ayarlanmadan yanıp sönen searchBar durumundan kaynaklandı.

Swift:

searchBar.backgroundImage = UIImage() 
+0

Hey, bu işe yarıyor! –

İlgili konular