Search code examples
iosxamarin.iosrotationscaleuiprogressview

UIProgressView disappear or doesn't scale when device rotate


I am using Xamarin.IOS, I have UIprogressView inside a UIScrollView with two buttons as well.

I am setting the UIprogressView frame by code in ViewWillLayoutSubviews method:

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

The problem is when I rotate the device from portrait to landscape, only the progressview will disappear. Meanwhile the next button is there and both progress view and next button have same Y!.

If I stopped using MyProgressView.ProgressTintColor I can see the progress view after rotation but it is not scaled.

Any idea how to fix it?

This is the UIProgressView I am talking about:

enter image description here


Solution

  • I fixed it by re-scale it at every rotate:

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