tirsdag 22. november 2011

Beware of layers in iOS!

When working a MonoTouch application, I got a design that involved transparency, rounded corners and shadows. I was happy to discover that this could all be done via the layers property so I added a utility method:

public static void ApplyDropShadow (UIButton imgView)
{
  imgView.Layer.ShadowColor = UIColor.FromRGB (0, 0, 0).CGColor;
  imgView.Layer.ShadowOffset = new SizeF (2, 2);
  imgView.Layer.ShadowOpacity = 1f;
  imgView.BackgroundColor = UIColor.Clear;
  imgView.Layer.ShadowRadius = 1.0f;
  imgView.Layer.BorderColor = UIColor.White.CGColor;
  imgView.Layer.BorderWidth = 0.7f;
  imgView.Layer.CornerRadius = 2f;
  imgView.Layer.MasksToBounds = true;
  imgView.ClipsToBounds = false;
}
but this yielded "horrible" scrolling performance. Took me a good many hours to discover the cause of the "jerky" scrolling, but the shadow part was the culprit.

As a temporary solution the shadows are now gone, and I am now looking at doing this using CoreGrahics. Some sample code for MonoTouch can be found here: 
http://sabonrai.wordpress.com/2009/09/03/monotouch-sample-core-graphics-and-uiimageview/

objective-c: http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/

Another option is to buy an iPhone 4gs as the scrolling is silky smooth on this device.
Fragmentation! :-)

Ingen kommentarer:

Legg inn en kommentar