2017-05-26 8 views
0

私はXamarin.IOSを使用しています。私はUIprogressViewをUIScrollViewの中に2つのボタンとともに備えています。デバイスが回転すると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 +あなたのボタンの高さ)。試してください –

答えて

0

を非表示にすることは回転:

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

は、あなたのヘルパーのフォルダに

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(); } 
     ); 
    } 
} 

、この方法を使用し、このUIProgressViewファイルを作成します。

がロード

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

を表示するために、私は、すべてで再スケール、それによってそれを修正し、それを

loadingOverlay.Hide(); 
+0

コメントありがとうございますが、私は水平方向の進捗状況を尋ねていました。質問を画像で更新しました。 –

関連する問題