2017-10-01 5 views
0

Voici à quoi ressemble mon écran. Il a un UIToolBar en bas et contient un UIBarButtonItem. Il fonctionnait très bien avant avant iOS 11.iOS 11: UIBarButtonItem à l'intérieur de l'UIToolbar disparaît

enter image description here

Mais dans iOS 11, la UIBarButtonItem montre à sa place. Il est affiché dans la barre d'état. Dans le simulateur, cela fonctionne très bien, et cela se voit à l'intérieur de la barre d'outils. Mais quand je le lance sur un iPhone 6s sous iOS 11. Il se montre comme sur l'écran ci-dessous.

enter image description here

est ici le code ..

public override void ViewDidAppear(bool animated) 
{ 
    base.ViewDidAppear(animated); 
    UIBarButtonItem[] bArray = { 
     getSetAsHomeButton(apiCall, this, 0), 
     new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace) 
    }; 
    SetToolbarItems(bArray, true); 
} 

public static UIBarButtonItem getSetAsHomeButton(ICommonApiCall commonApiCall, UIViewController controller, int status) 
{ 
    var view = new UIButton(); 
    view.Layer.CornerRadius = 8; 
    view.BackgroundColor = UIColor.White; 

    view.TranslatesAutoresizingMaskIntoConstraints = false; 
    view.WidthAnchor.ConstraintEqualTo(108).Active = true; 
    view.HeightAnchor.ConstraintEqualTo(32).Active = true; 

    var HomeIcon = new UILabel (new RectangleF (0, 0, 21, 21)); 
    HomeIcon.Font = FontAwesome.Font (22); 
    HomeIcon.Text = FontAwesome.FAHome; 
    HomeIcon.TextColor = PlatformConstants.PrimaryColor; 

    var HomeLabel = new UILabel (new RectangleF (25, 0, 64, 44)); 
    HomeLabel.Text = "Set as default"; 
    HomeLabel.Font = UIFont.FromName (PlatformConstants.PrimaryFont + "-Medium", 11); 
    HomeLabel.TextColor = PlatformConstants.PrimaryColor; 
    HomeLabel.Lines = 0; 
    HomeLabel.SizeToFit(); 

    view.AddSubview (HomeIcon); 
    view.AddSubview (HomeLabel); 

    HomeIcon.TranslatesAutoresizingMaskIntoConstraints = false; 
    HomeLabel.TranslatesAutoresizingMaskIntoConstraints = false; 

    var hSpaceLeading = NSLayoutConstraint.Create (HomeIcon, NSLayoutAttribute.Leading, 
            NSLayoutRelation.Equal, view, NSLayoutAttribute.Leading, 1, 6); 
    view.AddConstraint (hSpaceLeading); 

    var HomeIconCenterY = NSLayoutConstraint.Create (HomeIcon, NSLayoutAttribute.CenterY, 
           NSLayoutRelation.Equal, view, NSLayoutAttribute.CenterY, 1, 0); 
    view.AddConstraint (HomeIconCenterY); 

    var HomeLabelCenterY = NSLayoutConstraint.Create (HomeLabel, NSLayoutAttribute.CenterY, 
           NSLayoutRelation.Equal, view, NSLayoutAttribute.CenterY, 1, 0); 
    view.AddConstraint (HomeLabelCenterY); 

    var hSpace = NSLayoutConstraint.Create (HomeLabel, NSLayoutAttribute.Left, 
          NSLayoutRelation.Equal, HomeIcon, NSLayoutAttribute.Right, 1, 4); 
    view.AddConstraint (hSpace); 

    var HomeLabelWidth = NSLayoutConstraint.Create (HomeLabel, NSLayoutAttribute.Width, 
           NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 80); 
    view.AddConstraint (HomeLabelWidth); 

    view.LayoutIfNeeded(); 

    view.TouchUpInside += delegate { 
     SetAsHome (commonApiCall, controller, status, view).ContinueWith (t => Console.WriteLine (t.Exception), 
            TaskContinuationOptions.OnlyOnFaulted); 
    }; 

    return new UIBarButtonItem (view); 
} 

Toute aide est appréciée. Je vous remercie.

Répondre

1

Depuis iOS Auto Layout a été introduit dans les éléments UINavigationBar et UIToolbar. La meilleure façon de résoudre votre problème consiste donc à ajouter les contraintes appropriées.

Ici vous pouvez trouver plus d'aide et de détails sur la question: https://forums.developer.apple.com/thread/80075

Hope this résout votre problème.