我有一个被触摸操纵的图像。
让我们说,这是一个箭头的图像指向。在它被旋转180度之后,箭头现在向下,我想重置CGAffineTransform属性,这样它就会认为它已经转回0度了。
我想要这个,因为无论图像的角度是0还是180,我都需要平移,旋转,缩放等等。
提前谢谢。
编辑的Ater 5答复:
嗯,我不确定这些答案中是否有我想做的事。我很抱歉没说清楚。
为了防止上述问题和其他问题,我想在它被旋转180之后重新设置所有的东西。例如,一旦图像转到180度,CGAffineTransform属性就知道它已经转到180%了。我想在那个时候重置操作,所以CGAffineTransform认为它变成了0度,而不是180度,尽管图像在视觉上颠倒了。我希望在没有任何视觉变化的情况下发生这种情况,当它旋转到180度时。
希望这更清楚..。
发布于 2011-05-13 18:03:04
如果您试图重置转换,使图像显示为原来的样子,您可以简单地将转换设置为标识。
self.imageView.transform = CGAffineTransformIdentity如果要将任意转换应用于转换后的映像,最简单的方法是使用接受现有转换的CGAffineTransform方法。只需发送现有的转换。例如:
CGAffineTransform scale = CGAffineTransformMakeScale(zoom, 1);
self.imageView.transform = CGAffineTransformConcat(self.imageView.transform, scale);如果您真的需要图像,因为它的出现,没有任何转换,您将不得不把它拉回另一个图像。这也没那么难,但我不推荐它作为你的第一个解决方案。此代码适用于任意视图的UIView类别上下文,包括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;
}发布于 2017-10-15 15:22:50
Swift 3,Swift 4和Swift 5
您可以使用以下内容重置CGAffineTransform:
self.imageView.transform = CGAffineTransform.identity较短的版本就是.identity,如下所示:
self.imageView.transform = .identity发布于 2011-05-13 18:39:40
昨天做了一些类似但简单的事情。
查找任何现有的转换值。然后,将其作为新转换的抵消项。
见例子:
// Rotate right/clockwise
CGFloat radians = atan2f(imageView.transform.b, imageView.transform.a);
CGFloat degrees = radians * (180 / M_PI);
// Yeah yeah, I like degrees.
CGAffineTransform transform = CGAffineTransformMakeRotation((90 + degrees) * M_PI/180);
imageView.transform = transform;// Rotate left/anticlockwise
CGFloat radians = atan2f(imageView.transform.b, imageView.transform.a);
CGFloat degrees = radians * (180 / M_PI);
// Yeah yeah, I like degrees.
CGAffineTransform transform = CGAffineTransformMakeRotation((-90 + degrees) * M_PI/180);
imageView.transform = transform;这只是一个提示,如果您想要将现有的转换值相加到新的转换以形成正确的移动,那么这只是一个提示。用同样的方法来进行比例尺等。
一些人建议使用CABasicAnimation,并将其加性设置为YES。但不能让它起作用。
https://stackoverflow.com/questions/5995923
复制相似问题