CGAffineTransform重置 [英] CGAffineTransform Reset

查看:200
本文介绍了CGAffineTransform重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

3我有一个可以通过触摸操纵的图像。

3I have an image that gets manipulated by touch.

让我们说它是一个指向箭头的图像。旋转180度后,箭头指向现在,我想重置CGAffineTransform属性,以便它现在认为它已经回到0度。

Lets say its an image of an arrow that points up. After it's been rotated 180 degrees, so the arrow is pointing down now, I want to reset CGAffineTransform properties so that it thinks now its turned back to 0 degrees.

我想要这个,因为我必须翻译,旋转,缩放等,无论图像的角度是0还是180.

I want this because I have to translate, rotate, scale etc whether the image's angle is 0 OR 180.

提前致谢。

编辑Ater 5回复:

嗯,我不确定这些答案是否有任何答案我想要的是什么。我为不清楚而道歉。

Hmm, I am not sure if any of these answers do what I wanted to. I apologize for not being clear.


  1. 触摸箭头朝上的图像并向右移动 - 一切都很好。

  2. 用旋转手势旋转图像并转动180度 - 一切都很好

  3. 图像现在被触摸并向右移动 - 由于坐标是颠倒的,现在图像上下跳动使我的其他动画序列变得棘手。

为了防止上述问题和其他一些问题,我想要旋转180后重置所有内容。例如,一旦图像变为180度,CGAffineTransform属性就知道它变为180%。我想在那时重置这些属性,所以CGAffineTransform认为它转0度而不是180度,尽管图像是视觉上倒置的。我希望这可以在没有任何视觉变化的情况下发生,很快就会旋转到180度。

To prevent above problem and some other ones, I want to reset everything after it has been rotated 180. For example once the image turned 180deg, CGAffineTransform properties knows it's turned 180%. I want to reset the poperties at that time so CGAffineTransform thinks its turned 0 degrees instead of 180, eventhough the image is upside down visually. I want this to happen without any visual changes, soon as its rotated to 180deg.

希望这更清楚....

Hope this is clearer....

推荐答案

如果您尝试重置转换,以便图像按原样显示,则只需将转换设置回标识即可。

If you are trying to reset the transformation, so that the image appears as it did originally, you can simply set the transform back to the identity.

self.imageView.transform = CGAffineTransformIdentity

如果要对变换后的图像应用任意变换,最简单的方法是使用接收现有变换的CGAffineTransform方法。只需发送现有的转型。例如:

If you want to apply arbitrary transformations to the transformed image, the easiest thing to do would be to use the CGAffineTransform methods that take in an existing transformation. Just send in the existing transformation. For example:

CGAffineTransform scale = CGAffineTransformMakeScale(zoom, 1);
self.imageView.transform = CGAffineTransformConcat(self.imageView.transform, scale);

如果您真的需要图像,因为它看起来没有任何转换,您将不得不画它回到另一个图像。这也不是那么难,但我不推荐它作为你的第一个解决方案。此代码适用于任意视图的UIView类别的上下文,包括UIImageView:

If you REALLY need the image as it appears without any transformation at all, you'll have to draw it back into another image. That's not that hard either, but I don't recommend it as your first solution. This code works in the context of a UIView category for an arbitrary view, including a UIImageView:

- (UIImage *) capture {
    CGRect screenRect = self.frame;
    CGFloat scale = [[UIScreen mainScreen] scale];
    UIGraphicsBeginImageContextWithOptions(screenRect.size, YES, scale);

    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [[UIColor blackColor] set];
    CGContextFillRect(ctx, screenRect);

    [self.layer renderInContext: ctx];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return newImage;
}

这篇关于CGAffineTransform重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆