2017-05-26 52 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

谢谢你的评论,但是,我要求的是水平进度视图。我用图像更新了我的问题。 –