我在将MISvmCross项目中的UIScrollable控件添加到屏幕时遇到问题。 我已经在视图的子视图中添加了一个scrollView控件,然后添加了 我很感激任何帮助。 以下是视图加载的代码:
public override void ViewDidLoad()
{
View = new UniversalView();
base.ViewDidLoad();
this.scrollView = new UIScrollView(new RectangleF(0, 0, this.View.Frame.Width, this.View.Frame.Height - this.NavigationController.NavigationBar.Frame.Height));
this.View.AddSubview(scrollView);
var lastName = new UITextField(new RectangleF(0f, 0f, 320f, 40f));
lastName.Placeholder = "Last Name";
this.View.AddSubview(lastName);
var firstName = new UITextField(new RectangleF(0f, 50f, 320f, 40f));
firstName.Placeholder = "First Name";
this.View.AddSubview(firstName);
var middleInitial = new UITextField(new RectangleF(0f, 100f, 320f, 40f));
middleInitial.Placeholder = "Middle Initial";
this.View.AddSubview(middleInitial);
var phoneNumber = new UITextField(new RectangleF(0f, 150f, 320f, 40f));
phoneNumber.Placeholder = "Phone Number";
this.View.AddSubview(middleInitial);
var streetAddress = new UITextField(new RectangleF(0f, 200f, 320f, 40f));
streetAddress.Placeholder = "Street Address";
this.View.AddSubview(streetAddress);
var city = new UITextField(new RectangleF(0f, 250f, 320f, 40f));
city.Placeholder = "City";
this.View.AddSubview(city);
var state = new UITextField(new RectangleF(0f, 200f, 320f, 40f));
state.Placeholder = "State";
this.View.AddSubview(state);
var zip = new UITextField(new RectangleF(0f, 250f, 320f, 40f));
zip.Placeholder = "Zip Code";
this.View.AddSubview(zip);
var date = new UITextField(new RectangleF(0f, 200f, 320f, 40f));
date.Placeholder = "Date of Appointment";
this.View.AddSubview(date);
var agentID = new UITextField(new RectangleF(0f, 250f, 320f, 40f));
agentID.Placeholder = "Agent ID";
this.View.AddSubview(agentID);
var set = this.CreateBindingSet<AddScope, AddScopeViewModel>();
set.Bind(lastName).To(vm => vm.BeneficiaryLastName);
set.Bind(firstName).To(vm => vm.BeneficiaryFirstName);
set.Bind(middleInitial).To(vm => vm.BeneficiaryMiddleInitial);
set.Bind(phoneNumber).To(vm => vm.BeneficiaryPhone);
set.Bind(streetAddress).To(vm => vm.BeneficiaryStreetAddress);
set.Bind(city).To(vm => vm.BeneficiaryCity);
set.Bind(state).To(vm => vm.BeneficiaryState);
set.Bind(zip).To(vm => vm.BeneficiaryZip);
set.Bind(date).To(vm => vm.DateOfAppointment);
set.Bind(agentID).To(vm => vm.AgentID);
set.Apply();
}
答案 0 :(得分:1)
它认为该示例代码的主要问题是您没有将子UIView
添加到UIScrollView
快速修复可能是使用scrollview作为主视图:
public override void ViewDidLoad()
{
View =
new UIScrollView(new RectangleF(0, 0, this.View.Frame.Width,
this.View.Frame.Height))
{
ContentSize = new SizeF(320, 800),
BackgroundColor = UIColor.Red
};
base.ViewDidLoad();
var lastName = new UITextField(new RectangleF(0f, 0f, 320f, 40f));
lastName.Placeholder = "Last Name";
this.View.AddSubview(lastName);
var firstName = new UITextField(new RectangleF(0f, 50f, 320f, 40f));
firstName.Placeholder = "First Name";
this.View.AddSubview(firstName);
var middleInitial = new UITextField(new RectangleF(0f, 100f, 320f, 40f));
middleInitial.Placeholder = "Middle Initial";
this.View.AddSubview(middleInitial);
var phoneNumber = new UITextField(new RectangleF(0f, 150f, 320f, 40f));
phoneNumber.Placeholder = "Phone Number";
this.View.AddSubview(middleInitial);
var streetAddress = new UITextField(new RectangleF(0f, 200f, 320f, 40f));
streetAddress.Placeholder = "Street Address";
this.View.AddSubview(streetAddress);
var city = new UITextField(new RectangleF(0f, 250f, 320f, 40f));
city.Placeholder = "City";
this.View.AddSubview(city);
var state = new UITextField(new RectangleF(0f, 200f, 320f, 40f));
state.Placeholder = "State";
this.View.AddSubview(state);
var zip = new UITextField(new RectangleF(0f, 250f, 320f, 40f));
zip.Placeholder = "Zip Code";
this.View.AddSubview(zip);
var date = new UITextField(new RectangleF(0f, 200f, 320f, 40f));
date.Placeholder = "Date of Appointment";
this.View.AddSubview(date);
var agentID = new UITextField(new RectangleF(0f, 250f, 320f, 40f));
agentID.Placeholder = "Agent ID";
this.View.AddSubview(agentID);
var set = this.CreateBindingSet<AddScope, AddScopeViewModel>();
set.Bind(lastName).To(vm => vm.BeneficiaryLastName);
set.Bind(firstName).To(vm => vm.BeneficiaryFirstName);
set.Bind(middleInitial).To(vm => vm.BeneficiaryMiddleInitial);
set.Bind(phoneNumber).To(vm => vm.BeneficiaryPhone);
set.Bind(streetAddress).To(vm => vm.BeneficiaryStreetAddress);
set.Bind(city).To(vm => vm.BeneficiaryCity);
set.Bind(state).To(vm => vm.BeneficiaryState);
set.Bind(zip).To(vm => vm.BeneficiaryZip);
set.Bind(date).To(vm => vm.DateOfAppointment);
set.Bind(agentID).To(vm => vm.AgentID);
set.Apply();
}