[SceneKit] Add AddAnimation overload that takes a SCNAnimation (#3192)
Fixes xamarin/xamarin-macios#3166 Apple broke `addAnimation:forKey:` API by changing `CAAnimation` parameter into a `ISCNAnimationProtocol` that was introduced in Xcode 9 (iOS 11 and company). We can't break the existing API but we can add an extension method that reuses the `CAAnimation` overload but takes a `SCNAnimation` and we turn the `SCNAnimation` into a `CAAnimation` behind the scenes. For XAMCORE_4_0 we corrected the protocol signature to take `ISCNAnimationProtocol` so there won't be a need for the extension method anymore.
This commit is contained in:
Родитель
49d3a50f26
Коммит
879a61faa7
|
@ -8,6 +8,7 @@ using XamCore.ObjCRuntime;
|
||||||
#if WATCH
|
#if WATCH
|
||||||
using AnimationType = global::XamCore.SceneKit.ISCNAnimationProtocol;
|
using AnimationType = global::XamCore.SceneKit.ISCNAnimationProtocol;
|
||||||
#else
|
#else
|
||||||
|
using XamCore.CoreAnimation;
|
||||||
using AnimationType = global::XamCore.CoreAnimation.CAAnimation;
|
using AnimationType = global::XamCore.CoreAnimation.CAAnimation;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -96,4 +97,18 @@ namespace XamCore.SceneKit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !WATCH && !XAMCORE_4_0
|
||||||
|
[iOS (11,0)]
|
||||||
|
[TV (11,0)]
|
||||||
|
[Mac (10,13,0, PlatformArchitecture.Arch64)]
|
||||||
|
static public partial class SCNAnimatableExtensions {
|
||||||
|
static public void AddAnimation (this ISCNAnimatable self, SCNAnimation animation, string key)
|
||||||
|
{
|
||||||
|
using (var ca = CAAnimation.FromSCNAnimation (animation))
|
||||||
|
using (var st = key != null ? new NSString (key) : null)
|
||||||
|
self.AddAnimation (ca, st);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,11 @@ namespace XamCore.SceneKit {
|
||||||
#endif
|
#endif
|
||||||
[NoWatch]
|
[NoWatch]
|
||||||
[Export ("addAnimation:forKey:")]
|
[Export ("addAnimation:forKey:")]
|
||||||
|
#if !XAMCORE_4_0
|
||||||
void AddAnimation (CAAnimation animation, [NullAllowed] NSString key);
|
void AddAnimation (CAAnimation animation, [NullAllowed] NSString key);
|
||||||
|
#else
|
||||||
|
void AddAnimation (ISCNAnimationProtocol scnAnimation, [NullAllowed] string key);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if XAMCORE_2_0
|
#if XAMCORE_2_0
|
||||||
#if XAMCORE_4_0
|
#if XAMCORE_4_0
|
||||||
|
@ -3503,7 +3507,6 @@ namespace XamCore.SceneKit {
|
||||||
[Watch (4, 0), TV (11, 0), Mac (10, 13, onlyOn64: true), iOS (11, 0)]
|
[Watch (4, 0), TV (11, 0), Mac (10, 13, onlyOn64: true), iOS (11, 0)]
|
||||||
[Export ("incremental")]
|
[Export ("incremental")]
|
||||||
bool Incremental { [Bind ("isIncremental")] get; set; }
|
bool Incremental { [Bind ("isIncremental")] get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Watch (3,0)]
|
[Watch (3,0)]
|
||||||
|
|
|
@ -56,7 +56,23 @@ namespace MonoTouchFixtures.SceneKit {
|
||||||
string key = "key";
|
string key = "key";
|
||||||
n.AddAnimation (a, key);
|
n.AddAnimation (a, key);
|
||||||
using (var s = new NSString (key))
|
using (var s = new NSString (key))
|
||||||
n.AddAnimation (a, key);
|
n.AddAnimation (a, s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AddAnimation_Overload ()
|
||||||
|
{
|
||||||
|
TestRuntime.AssertXcodeVersion (9,0);
|
||||||
|
|
||||||
|
using (var ca = CAAnimation.CreateAnimation ())
|
||||||
|
using (var a = SCNAnimation.FromCAAnimation (ca))
|
||||||
|
using (var n = SCNNode.Create ()) {
|
||||||
|
n.AddAnimation (a, "key");
|
||||||
|
n.RemoveAllAnimations ();
|
||||||
|
|
||||||
|
n.AddAnimation (a, null);
|
||||||
|
n.RemoveAllAnimations ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче