Xamarin和XCode:调整UIView和UITableView的大小
问题描述:
我有一个很长的屏幕(很多字段)。在XCode的结构:Xamarin和XCode:调整UIView和UITableView的大小
View
ScrollView
View
View
.
.
.
TableContainer (View)
TableView
TableContainer和的TableView具有高度。 当我在页面上 - 我设置高度TableView高度根据项数和增加TableView根据项目数量。 所有作品都可以。 但是,当我旋转设备 - TableView消失(高度重置为)。
类:
public partial class TrackingView: BaseView<TrackingViewModel>
{
public TrackingView() : base("TrackingView")
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
var source = new RetrieveShipmentDetailsViewSource(PortsTable, ShipmentDetailsCell.Key, ShipmentDetailsCell.Key);
PortsTable.Source = source;
var set = this.CreateBindingSet<TrackingModel, TrackingViewModel>();
set.Bind(ShipmentLabel).To(vm => vm.ShipmentNumber);
set.Bind(CustCodeLabel).To(vm => vm.Shipment.CustomerCode);
set.Bind(CustNameLabel).To(vm => vm.Shipment.CustomerName);
);
ViewModel.ShipmentLoadedSuccess += (sender, e) =>
{
InvokeOnMainThread(delegate
{
PortsTable.ReloadData();
UpdateView();
});
};
PortsTable.SeparatorStyle = UITableViewCellSeparatorStyle.None;
PortsTable.ReloadData();
set.Apply();
}
private void UpdateView()
{
if (ViewModel.Shipment != null && ViewModel.Shipment.VesselPorts != null)
{
PortsTable.ContentSize = new CGSize(MainView.ContentSize.Width, (ViewModel.Shipment.VesselPorts.Count * 200) + 55);
PortsTable.Frame = new CGRect(PortsTable.Frame.X, PortsTable.Frame.Y, PortsTable.Frame.Size.Width,
(ViewModel.Shipment.VesselPorts.Count * 200) + 55);
MainView.ContentSize = new CGSize(MainView.ContentSize.Width,
MainView.ContentSize.Height + (ViewModel.Shipment.VesselPorts.Count * 200) + 55);
}
}
}
我在新的iOS和我知道我的结构是不好的。 请教,如何重新加载TableView and ScrollView。 请帮助我。
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator NS_AVAILABLE_IOS(8_0);
它在Xcode与Objective-C的像这样实现:
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
// Code here will execute before the rotation begins.
// Equivalent to placing it in the deprecated method -[willRotateToInterfaceOrientation:duration:].
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
// Place code here to perform animations during the rotation.
// You can pass nil for this closure if not necessary.
// Reorganize views, or move child view controllers.
if (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
//Update UI
}
if (UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)) {
//Update UI
}
}completion:^(id<UIViewControllerTransitionCoordinatorContext> context){
// Code here will execute after the rotation has finished.
// Equivalent to placing it in the deprecated method -[didRotateFromInterfaceOrientation:].
// Do any cleanup, if necessary.
}];
}
它也可以发现
答
在Xcode中,当旋转设备使用此API更新您的UI Xamarin.iOS,ViewWillTransitionToSize。它可以用这样的C#实现:
public override void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTransitionCoordinator coordinator)
{
base.ViewWillTransitionToSize(toSize, coordinator);
coordinator.AnimateAlongsideTransition((IUIViewControllerTransitionCoordinatorContext) => {
if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.Portrait || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.PortraitUpsideDown)
{
//Update UI
}
if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeLeft|| UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeRight)
{
//Update UI
}
}, (IUIViewControllerTransitionCoordinatorContext) => {
//Transition Completion
});
}
谢谢@凯文,它适合我! 请问您是否可以帮我解决其他问题: 1. https://stackoverflow.com/questions/46224467/mvvmcross-hamburger-menu-for-ios 2. https://stackoverflow.com/questions/46202789/mvvmcross-platform-exceptions-mvxexception-could-load-plugin-assembly-for-t 谢谢。 – DaleYY