[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:
Alex Soto 2018-01-12 09:11:46 -06:00 коммит произвёл GitHub
Родитель 49d3a50f26
Коммит 879a61faa7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 36 добавлений и 2 удалений

Просмотреть файл

@ -8,6 +8,7 @@ using XamCore.ObjCRuntime;
#if WATCH
using AnimationType = global::XamCore.SceneKit.ISCNAnimationProtocol;
#else
using XamCore.CoreAnimation;
using AnimationType = global::XamCore.CoreAnimation.CAAnimation;
#endif
@ -96,4 +97,18 @@ namespace XamCore.SceneKit {
}
}
#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
[NoWatch]
[Export ("addAnimation:forKey:")]
#if !XAMCORE_4_0
void AddAnimation (CAAnimation animation, [NullAllowed] NSString key);
#else
void AddAnimation (ISCNAnimationProtocol scnAnimation, [NullAllowed] string key);
#endif
#if XAMCORE_2_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)]
[Export ("incremental")]
bool Incremental { [Bind ("isIncremental")] get; set; }
}
[Watch (3,0)]

Просмотреть файл

@ -56,7 +56,23 @@ namespace MonoTouchFixtures.SceneKit {
string key = "key";
n.AddAnimation (a, 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 ();
}
}
}