Bug 60023 - [High Sierra 10.13] Xamarin.Mac.CoreAnimation.CALayer.AnchorPoint is ignored
Summary: [High Sierra 10.13] Xamarin.Mac.CoreAnimation.CALayer.AnchorPoint is ignored
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-10-06 14:09 UTC by Kenny
Modified: 2017-10-09 11:25 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Sample app sourcecode (355.74 KB, application/octet-stream)
2017-10-06 14:12 UTC, Kenny
Attaching the sample in ObjC (31.54 KB, application/octet-stream)
2017-10-06 15:08 UTC, Kenny

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Kenny 2017-10-06 14:09:15 UTC
I have an application that rotates an imageview, using CoreAnimation.
The imageview should rotate around the center.
To do this, we change the anchorpoint.
This works on previous OS versions (El Capitan, Mountain lion, Sierra, ..)
When running the application on macOS High Sierra, the behaviour of the application changes:
Setting the anchorpoint makes no difference, it always rotates around the same point, no matter what the anchorpoint is set to.

I created a sample app to illustrate this (app + source code attached)
I also recreated the same app in ObjC, to verify this was a bug in Mono, not CoreAnimation itself.

Currently using Mono JIT compiler version (d15-3/14f2c81 Thu Aug 24 10:33:52 EDT 2017)

Relevant code:

NSImageView view = new NSImageView();
view.WantsLayer = true;
view.Layer.BackgroundColor = NSColor.Red.CGColor;
view.Frame = new CGRect(x, 100, 24, 24);
statusView.Layer.AnchorPoint = pAnchorPoint; // Does not work on High Sierra!
statusView.Animates = true;
CABasicAnimation animation = CABasicAnimation.FromKeyPath(@"transform.rotation.z");
animation.From = NSNumber.FromFloat(0.0f);
animation.To = NSNumber.FromFloat(2 * (float)Math.PI);
animation.Duration = 1f;
animation.RepeatCount = float.PositiveInfinity;
statusView.Layer.AddAnimation(animation, @"SpinAnimation");
Comment 1 Kenny 2017-10-06 14:12:23 UTC
Created attachment 25171 [details]
Sample app sourcecode
Comment 2 Chris Hamons 2017-10-06 14:19:50 UTC
Can you attach your obj-c sample as well?

Are you compiling both C# and obj-c using the same exact Xcode version and with the same version in your info.plist.

Apple sometimes changes behavior when linking against a new SDK or when targeting a certain version.
Comment 3 Kenny 2017-10-06 15:08:46 UTC
Created attachment 25173 [details]
Attaching the sample in ObjC
Comment 4 Chris Hamons 2017-10-06 21:16:52 UTC
So the obj-c and c# sample didn't exactly match. I re-did the C# to match with:

	NSImageView view = new NSImageView ();
	View.AddSubview (view);

	view.WantsLayer = true;
	view.Layer.BackgroundColor = NSColor.Red.CGColor;
	view.Frame = new CGRect (100, 100, 24, 24);
	view.Layer.AnchorPoint = new CGPoint(.5, .5); 
	view.Animates = true;
	CABasicAnimation anim = CABasicAnimation.FromKeyPath("transform.rotation.z");
	anim.From = NSNumber.FromFloat(0);
	anim.To = NSNumber.FromFloat((float)(2 * Math.PI));
	anim.Duration = 1;
	anim.RepeatCount = float.PositiveInfinity;
	view.Layer.AddAnimation(anim, "SpinAnimation");

and I'm still seeing it.

The strange thing is that 

view.Layer.AnchorPoint in c# is {{X=0.5, Y=0.5}}

while in obj-c:

po view.layer.anchorPoint
(x = 0, y = 0)
Comment 5 Chris Hamons 2017-10-06 21:33:42 UTC
However, NSLog / CWL shows the same values for both...
Comment 6 Chris Hamons 2017-10-06 21:46:56 UTC
There is some setting inside the storyboard causing this madness. If I replace the XS provided storyboard w\ one from the obj-c project, it starts rotating "correctly".

Diffing now...
Comment 7 Chris Hamons 2017-10-06 21:52:21 UTC
You need to add this line to your sample:

View.WantsLayer = true;

The actual container view needs to be layer based for rotation to work apparently in 10.13.

Apple made a huge number of layer based changes in 10.13, breaking some stuff, and this is one instance of that.

If you compare the storyboards, the one from Apple sets WantsLayer to true in the container view:

   <view key="view" wantsLayer="YES" id="m2S-Jp-Qdl">
and ours does not. I'll look at getting the template fixed up if it isn't already. You can also just edit your storyboard in IB (or a text editor) and fix this if you don't want to in code.
Comment 8 Chris Hamons 2017-10-06 21:56:46 UTC
Note that is a Capital V not lower v. The View of your View Controller has to be wanting layers.
Comment 9 Kenny 2017-10-09 11:25:31 UTC
Looks like that indeed works.
Thanks for the workaround!