gpt4 book ai didi

xamarin.ios - 尝试使用 Transform 在 MonoTouch 中旋转 UIView

转载 作者:行者123 更新时间:2023-12-04 19:16:09 28 4
gpt4 key购买 nike

我定义了一个 UIControl,其中我使用 MonoTouch.CoreGraphics 类来绘制一些项目,并通过 AddSubview 将 UIControl 放入 UIView。我正在尝试观察并转动整个事物以模拟类似于时钟或表盘上分针或秒针的运动。我的印象是我可以通过 UIView 上的 Transform 做到这一点。

我的 UIView 的名称是容器。我试过了:

    container.Transform.Rotate(-0.78f);

我也试过:
    CGAffineTransform t = CGAffineTransform.MakeIdentity();
t.Rotate(-0.78f);
container.Transform = t;

我也试过:
    CGAffineTransform t = CGAffineTransform.MakeRotation(-0.78f);
container.Transform = t;

我也试过这个和它的其他组合:
    UIView.BeginAnimations("rotate");
UIView.SetAnimationDuration(0.5);
container.Transform.Rotate((float)Math.PI);
UIView.CommitAnimations();

以上都没有对我的显示产生任何影响。它一点也不旋转或移动。所有与 iOS 相关的帖子都引用了 CGAffineTransformRotate,但我找不到 Mono 完全匹配的内容,并且我假设这与我在上面所做的等效。有没有其他方法可以让我的 View 旋转?

最佳答案

你走在正确的轨道上。我正在开发一个大型游戏,并在我的代码中到处执行此操作。这是我可以给你的最简单的例子:

using MonoTouch.CoreGraphics;

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

就是这样。

这些示例很少,尤其是 MakeRotation 函数以弧度表示(因此使用 pi 转换为度数)。

关于xamarin.ios - 尝试使用 Transform 在 MonoTouch 中旋转 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9453733/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com