我正在尝试从CATiledLayer
.
根据此关闭的错误报告,设置CATiledLayer.FadeDuration
静态属性不起作用也不应该这样做:https ://bugzilla.novell.com/show_bug.cgi?id=648993
Objective-C 中建议的解决方案是子类化CATiledLayer
:How to change iphone CATiledLayer fadeDuration? . 我已经在 MonoTouch 中实现了这一点,但视图中没有绘制任何内容,尽管DrawInContext
按预期调用。
重现该问题的完整代码如下。一旦我删除[Export("fadeDuration")]
一切正常(但有动画)。
提前感谢您的帮助。
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 = UIColor.Green;
var view = new ContentView ();
view.BackgroundColor = UIColor.White;
view.Frame = window.Bounds;
window.AddSubview (view);
window.MakeKeyAndVisible ();
return true;
}
}