2017-05-26 53 views
0

我正在使用Xamarin.IOS,在兩個按鈕的UIScrollView中也有UIprogressView。UIProgressView在設備旋轉時消失或不縮放

我對代碼ViewWillLayoutSubviews方法設置UIprogressView框架:

 CGRect newFrame; 
     newFrame.Width = MyScrollView.Frame.Width/2; 
     newFrame.Location = new CGPoint(0, NextButton.Frame.Y); 
     MyProgressView.Frame = newFrame; 
     MyProgressView.Transform = CGAffineTransform.MakeScale(1, 20f); 
     MyProgressView.TrackTintColor = CustomColors.CustomColors.GetColor(CustomColors.CustomColors.ColorGray); 
     MyProgressView.ProgressTintColor = CustomColors.CustomColors.GetColor(CustomColors.CustomColors.ColorBlue); 

問題是,當我從縱向到橫向旋轉裝置,只有progressview就會消失。同時下一個按鈕在那裏,進度視圖和下一個按鈕都有相同的Y !.

如果我停止使用MyProgressView.ProgressTintColor我可以看到旋轉後的進度視圖,但沒有縮放。

任何想法如何解決它?

這是我講的是UIProgressView:

enter image description here

+0

它將如果使用更好的自動版式。 –

+0

newFrame.Location = new CGPoint(0,NextButton.Frame.Y + you Buttons height)。試試這個 –

回答

0

我固定它通過重新大規模它在每一個旋轉:

public override void WillAnimateRotation(UIInterfaceOrientation toInterfaceOrientation, double duration) 
{ 
    progressView.Transform = CGAffineTransform.Scale(progressView.Transform,1, 20f); 
} 
1

在助手文件夾中創建該文件UIProgressView

LoadingOverlay.cs

public class LoadingOverlay : UIView 
    { 
     // control declarations 
     UIActivityIndicatorView activitySpinner; 
     UILabel loadingLabel; 

    public LoadingOverlay(CGRect frame) : base(frame) 
    { 
     // configurable bits 
     BackgroundColor = UIColor.Black; 
     Alpha = 0.75f; 
     AutoresizingMask = UIViewAutoresizing.All; 

     nfloat labelHeight = 22; 
     nfloat labelWidth = Frame.Width - 20; 

     // derive the center x and y 
     nfloat centerX = Frame.Width/2; 
     nfloat centerY = Frame.Height/2; 

     // create the activity spinner, center it horizontall and put it 5 points above center x 
     activitySpinner = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.WhiteLarge); 
     activitySpinner.Frame = new CGRect(
      centerX - (activitySpinner.Frame.Width/2), 
      centerY - activitySpinner.Frame.Height - 20, 
      activitySpinner.Frame.Width, 
      activitySpinner.Frame.Height); 
     activitySpinner.AutoresizingMask = UIViewAutoresizing.All; 
     AddSubview(activitySpinner); 
     activitySpinner.StartAnimating(); 

     // create and configure the "Loading Data" label 
     loadingLabel = new UILabel(new CGRect(
      centerX - (labelWidth/2), 
      centerY + 20, 
      labelWidth, 
      labelHeight 
      )); 
     loadingLabel.BackgroundColor = UIColor.Clear; 
     loadingLabel.TextColor = UIColor.White; 
     loadingLabel.Text = "Loading Data..."; 
     loadingLabel.TextAlignment = UITextAlignment.Center; 
     loadingLabel.AutoresizingMask = UIViewAutoresizing.All; 
     AddSubview(loadingLabel); 

    } 

    /// <summary> 
    /// Fades out the control and then removes it from the super view 
    /// </summary> 
    public void Hide() 
    { 
     UIView.Animate(
      0.5, // duration 
      () => { Alpha = 0; }, 
      () => { RemoveFromSuperview(); } 
     ); 
    } 
} 

,並用這樣的方式

顯示加載

var loadingOverlay = new LoadingOverlay(UIScreen.MainScreen.Bounds); 
View.Add(loadingOverlay); 

,並隱藏

loadingOverlay.Hide(); 
+0

謝謝你的評論,但是,我要求的是水平進度視圖。我用圖像更新了我的問題。 –