2017-09-14 9 views
0

매우 긴 화면 (많은 필드)이 있습니다. 엑스 코드 구조 :Xamarin 및 XCode : UIView 및 UITableView 크기 조정

View 
    ScrollView 
    View 
     View 
     . 
     . 
     . 
     TableContainer (View) 
     TableView 

TableContainer하고있는 TableView 높이를 0있다. 제가 페이지에 올라갈 때 - 높이를 으로 설정합니다. 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); 
      } 
     } 
    } 

나는 아이폰 OS의 새로운 그리고 난 내 구조가 좋지 않은 것을 알고있다. 조언, 제발, 다시로드하는 방법 TableViewScrollView. 도와주세요.

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator NS_AVAILABLE_IOS(8_0); 

이 같은 목표 - 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. 

           }]; 
} 

장치를 회전 할 때

답변

1

은 엑스 코드에서, 당신의 UI를 업데이트하려면이 API를 사용하여 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 
     }); 
    } 
+0

고맙습니다. 다른 문제로 도와주세요 : 1. https://stackoverflow.com/questions/46224467/mvvmcross-hamburger-menu-for-ios 2. https://stackoverflow.com/questions/46202789/mvvmcross-platform-exceptions-mvxexception-could-not-load-plugin-for-t 감사합니다. – DaleYY