UISearchBar没有调整电话轮换的大小

时间:2018-03-21 19:49:37

标签: c# ios xamarin.ios mkmapview uisearchbar

我遇到的问题是我的UISearchBar在手机旋转时没有调整大小,除非我触摸搜索栏以使其具有焦点(见下图)。

创建搜索栏并将其作为子视图添加到UIMapView。见代码。

创建搜索栏:

public UISearchController DefineSearchController()
{
    _searchResultsController = new SearchResultsVC(_mapView);
    _searchResultsController.searchItemSelected += PlaceSelect;


    _searchUpdater = new SearchResultsUpdator();
    _searchUpdater.UpdateSearchResults += _searchResultsController.Search;

    //add the search controller
    var searchController = new UISearchController(_searchResultsController)
    {
        SearchResultsUpdater = _searchUpdater
    };

    var scb = searchController.SearchBar;

    scb.SizeToFit();
    scb.SearchBarStyle = UISearchBarStyle.Minimal;

    var img = UIImage.FromBundle("tabSpace");
    scb.SetBackgroundImage(img, UIBarPosition.Top, UIBarMetrics.Default);

    var textField = scb.ValueForKey(new NSString("searchField")) as UITextField;
    if (textField != null)
    {                
        var backgroundView = textField.Subviews[0];

        if (backgroundView != null)
        {
            backgroundView.BackgroundColor = UIColor.White;
            backgroundView.Layer.BorderColor = AppColour.PersianBlue.GetUIColour().CGColor;
            backgroundView.Layer.BorderWidth = 1;
            backgroundView.Layer.CornerRadius = 10;
            backgroundView.ClipsToBounds = true;

        }

    }

    var localEnterPoI = NSBundle.MainBundle.LocalizedString("placeHolderSearchForLocation", "Enter a PoI to search for");
    scb.Placeholder = localEnterPoI; 

    searchController.Delegate = new SearchControllerDelegate();
    searchController.HidesNavigationBarDuringPresentation = false;

    return searchController;
}

添加到子视图中:

        //Define Search Controller
        _mapSearchManager = new MapSearchManager(_mapView);
        _searchController = _mapSearchManager.DefineSearchController();
        var scb = _searchController.SearchBar;
        _mapView.AddSubview(scb);

        NSLayoutConstraint.ActivateConstraints(new NSLayoutConstraint[]{
            scb.TopAnchor.ConstraintEqualTo(_mapView.TopAnchor, 30),
            scb.LeadingAnchor.ConstraintEqualTo(_mapView.LeadingAnchor, 10),
            scb.TrailingAnchor.ConstraintEqualTo(_mapView.LeadingAnchor, -10),
        });

我进行了广泛的搜索,只能找到一个类似的问题: UISearchBar doesn't resize when frame is resized in IOS 11

我实施了这两个建议,但它没有任何区别。

是否有其他人对此有所了解或知道可能的解决方案。

干杯

Portait Mode

Rotated

Rotated with focus

0 个答案:

没有答案