Sloppy ugly rotation of OwnerDrawnElement

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Sloppy ugly rotation of OwnerDrawnElement

guivho
Hi,

I need an element that has a caption at the left side, and a
disclosure indicator preceded by a dynamic subview on the right side.

Following element class works as expected, but behaves uncleanly when I rotate the device:

  public class SchemeElement : OwnerDrawnElement
  {

    public SchemeElement (UITableViewCellStyle style, string key) : base (style, key)
    {
    }

    public override void Draw (RectangleF bounds, MonoTouch.CoreGraphics.CGContext context, UIView view)
    {
      context.SetFillColor (MCColor.BackgroundColor.CGColor);
      context.FillRect (bounds);

      foreach (var v in view.Subviews) {
        v.RemoveFromSuperview ();
      }

      view.Add( new UILabel (bounds) {
        Text = "My text",
        TextColor = MCColor.TextColor,
        Font = MCFont.ButtonFont,
        Frame = new RectangleF (10, 0, 100, bounds.Height),
        BackgroundColor = MCColor.BackgroundColor,
      });

      // add subview that will have a frame.X of bounds.Width - 30 - subview.Width
      view.Add ( Config.SchemeShortTitle (bounds.Width - 30, (bounds.Height - 32) / 2));

      // add disclosure indicator size is 11 by 42, at X=bounds.Width - 20 and Y=1
      view.Add( new UIImageView () {
        Frame = new RectangleF (bounds.Width - 20, 1, 11, 42),
        Image = UIImage.FromFile ("Images/Img/accessory.png")
      });
    }

    public override float Height (RectangleF bounds)
    {
      return 44f;
    }
  }

Both subviews are still visible at the beginning of the rotation to
landscape mode, disappear by the time the rotation is finished, and
appear as desired in the rotated element.

This is really sloppy and ugly, and probably caused by the way I coded
the element.

Without the RemoveFromSuperView, both subviews appear twice: once at the
location of their portrait coordinates and at the desired landscape
coordinates.

Is there a better way to code such an element?

Please advise,

Thanks in advance,


Guido


_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch