我想知道为什么不能像通常在Swift中那样设置view.Frame的值。现在,我正在使用C#Xamarin应用程序,并尝试调整UIView的大小,但是它没有响应任何方法,因此始终保持不变。当我尝试更改View.Frame


  “无法修改'UIView.Frame'的返回值,因为它不是
  变量”


。我试图更改可以适合屏幕的UIView框架,但是此选项不起作用。如何更改适合每个屏幕的UIView框架?

        public void NotchNavBarCreator(UIView bar, UINavigationBar barItem) {
           CGRect barfr = bar.Frame;
           CGRect baritfr = barItem.Frame;
           barfr.Width = this.View.Bounds.Width;
           baritfr.Width = this.View.Bounds.Width;
           bar.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
        }

最佳答案

您必须分配Frame变量,如下所示:

bar.Frame = new CGRect(x: 0, y: 0, width: 123, height: 321);

因此,如果您只想更改Width,请执行以下操作:
//create a rect based on the old values + the new width value
barfr.Frame = new CGRect(x: barfr.Frame.X, y: barfr.Frame.Y, width: this.View.Bounds.Width, height: barfr.Frame.Height);

09-05 22:33
查看更多