2017-10-01 10 views
0

これは私の画面がどのように見えるのかです。最下部にUIToolBarがあり、そのUIBarButtonItemが含まれています。それは、iOS 11.iOS 11:UIToolbar内のUIBarButtonItemがその場所から外れます

enter image description here

前に前に罰金働いていた。しかしiOSの11で、UIBarButtonItemは、その場所を示しています。これはステータスバーに表示されています。シミュレータでは正常に動作しており、ツールバーの中に表示されます。しかし、iOS 11を実行しているiPhone 6でこれを実行すると、下の画面のように表示されます。

enter image description here

ここでは、コード..

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); 
} 

すべてのヘルプは高く評価されます。ありがとうございました。

答えて

1

iOS自動レイアウトがUINavigationBarとUIToolbar要素に導入されたため、したがって、問題を解決する最善の方法は、適切な制約を追加することです。これはあなたの問題を解決し https://forums.developer.apple.com/thread/80075

希望:

ここでは、この問題に関するいくつかのより多くの助けと詳細を見つけることができます。

関連する問題