无法对 UIImageView 应用多重转换

Can't apply multiple transformation to UIImageView

我无法找出为什么我的转换未应用于 Xamarin 中的 UIImageView iOS。

代码如下:

CGAffineTransform transform = new CGAffineTransform();

transform.Rotate((float)Math.PI / 2);
transform.Scale(0.8f, 0.8f);

this.imageViewOverlay = new UIImageView
{ 
    ContentMode = UIViewContentMode.Center,
    BackgroundColor = UIColor.Clear,
    Opaque = false,
    Frame = new CGRect(0,0,this.View.Bounds.Width, this.View.Bounds.Height),
    Transform = transform
};

我以前的做法是这样的

Transform = CGAffineTransform.MakeRotation((float)Math.PI / 2)

但不幸的是,当你想使用它两次时,第二次正在清除之前的转换。

我正在使用

Xamarin.iOS: 版本:8.6.0.41(企业版)

操作系统: Mac OS X 10.10.3

XCode:版本 6.3.1 (6D1002)

谢谢!

您原来的 CGAffineTransform 是空的(全是 00),结构的默认值,并且 不是 身份转换,在其上您可以构建一些东西。 IOW 使所有后续调用(数学运算)return 成为一个空调用。

您可以从非空转换开始,例如

var transform = CGAffineTransform.MakeRotation((float)Math.PI / 2);
transform.Scale(0.8f, 0.8f);

或者您可以从身份转换开始,例如

var transform = CGAffineTransform.MakeIdentity ();
transform.Rotate ((nfloat) Math.PI / 2);
transform.Scale ((nfloat) 0.8f, (nfloat) 0.8f);