Trying to use Transform to rotate a UIView in MonoTouch

I have a UIControl in which I used the MonoTouch.CoreGraphics classes to draw some elements and placed the UIControl in a UIView through AddSubview. I'm trying to take a look and flip it all over to mimic something like the movement of a minute or second hand on a watch or dial. I get the impression that I can do this with Transform on a UIView.

The name of my UIView is a container. I tried:

container.Transform.Rotate(-0.78f); 

I also tried:

  CGAffineTransform t = CGAffineTransform.MakeIdentity(); t.Rotate(-0.78f); container.Transform = t; 

I also tried:

  CGAffineTransform t = CGAffineTransform.MakeRotation(-0.78f); container.Transform = t; 

I also tried this and its other combinations:

  UIView.BeginAnimations("rotate"); UIView.SetAnimationDuration(0.5); container.Transform.Rotate((float)Math.PI); UIView.CommitAnimations(); 

None of the above have affected my display. It does not rotate or move in the slightest degree. All iOS related posts relate to CGAffineTransformRotate, but I cannot find an exact Mono match for this, and I assume this is equivalent to what I do above. Is there any other way that I should try to turn my mind around?

+4
source share
1 answer

You are on the right track. I have a big game under development and do it all over my code. Here is the simplest example I can give you:

 using MonoTouch.CoreGraphics; float degrees = 15; UIView aView = new UIView(new RectangleF(10,10,10,10)); aView.Transform = CGAffineTransform.MakeRotation(3.14159f * degrees / 180f); 

What is it.

The examples are sparse, especially the fact that the MakeRotation function is in radians (therefore, using pi to convert to degrees).

+2
source

Source: https://habr.com/ru/post/1398469/


All Articles