我正在尝试从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;
}
}
答案 0 :(得分:2)
您没有保留对UIWindow的引用,这意味着它可以被收集和发布。
我重写了你的课程:
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;
}
}
}
并将其放在基于窗口的项目的默认项目模板中,并按预期工作。