开发者

Can't set CATiledLayer.FadeDuration in MonoTouch

I'm trying to remove fading animation from CATiledLayer.

Setting CATiledLayer.FadeDuration static property doesn't work and is not supposed to, according to this closed bug report: https://bugzilla.novell.com/show_bug.cgi?id=648993

The suggested solution in Objective-C is to subclass CATiledLayer: How to change iphone CATiledLayer fadeDuration?. I've implemented this in MonoTouch but nothing is being drawn in the view, although DrawInContext is called as expected.

The complete code to reproduce the problem is below. As soon as I remove [Export("fadeDuration")] everything works (but with animation).

Thanks in advance for any help.

using System;
using System.Drawing;
using MonoTouch.CoreAnimation;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;

[Register("NoFadeTiledLayer")]
public class NoFadeTiledLayer : CATiledLayer {

 public NoFadeTiledLayer () : base() {}
 public NoFadeTiledLayer (IntPtr handle) : base(handle) {}

 public override void DrawInContext (MonoTouch.CoreGraphics.CGContext ctx) {
   // This is being called everytime
   base.DrawInContext (ctx); 
 }

 [Export("fadeDuration")]
 public static new double FadeDuration () {
  return 0;
 }
}

public class ContentView : UIView {

 [Export("layerClass")]
 public static Class LayerClass () {
  return new Class (typeof(NoFadeTiledLayer));
 }

 public override void Draw (RectangleF rect) {
  DrawString ("Lorem ipsum", rect, UIFont.SystemFontOfSize (15));
 }
}


[Register("AppDelegate")]
public class AppDelegate : UIApplicationDelegate {

 static void Main (string[] args) {
  UIApplication.Main (args, null, "AppDelegate");
 }

 public override bool FinishedLaunching (UIApplication app, NSDictionary options) {
  var window = new UIWindow (UIScreen.MainScreen.ApplicationFrame);
  window.BackgroundColor = UIC开发者_如何转开发olor.Green;
  var view = new ContentView ();
  view.BackgroundColor = UIColor.White;
  view.Frame = window.Bounds;
  window.AddSubview (view);
  window.MakeKeyAndVisible ();

  return true;
 }
}


You aren't keeping a reference to your UIWindow, meaning it can be collected and released.

I rewrote your class like so:

using System;
using System.Drawing;
using MonoTouch.CoreAnimation;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;

namespace FadeTest
{
    [Register("NoFadeTiledLayer")]
    public class NoFadeTiledLayer : CATiledLayer
    {

        public NoFadeTiledLayer () : base()
        {
        }

        public NoFadeTiledLayer (IntPtr handle) : base(handle)
        {
        }

        public override void DrawInContext (MonoTouch.CoreGraphics.CGContext ctx)
        {
            // This is being called everytime
            base.DrawInContext (ctx); 
        }

        [Export("fadeDuration")]
        public static new double FadeDuration
        {
            get
            {
                return 0;
            }
        }
    }

    public class ContentView : UIView
    {

        [Export("layerClass")]
        public static Class LayerClass ()
        {
            return new Class (typeof(NoFadeTiledLayer));
        }

        public override void Draw (RectangleF rect)
        {
            DrawString ("Lorem ipsum", rect, UIFont.SystemFontOfSize (15));
        }
    }

    public partial class AppDelegate : UIApplicationDelegate
    {
        static void Main (string[] args)
        {
            UIApplication.Main (args, null, "AppDelegate");
        }

        public override bool FinishedLaunching (UIApplication app, NSDictionary options)
        {
            window = new UIWindow (UIScreen.MainScreen.ApplicationFrame);
            window.BackgroundColor = UIColor.Green;
            var view = new ContentView ();
            view.BackgroundColor = UIColor.White;
            view.Frame = window.Bounds;
            window.AddSubview (view);
            window.MakeKeyAndVisible ();

            return true;
        }
    }
}

and placed it in the default project template for a window based project, and it worked as expected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜