我如何从图像中转换图像以使其看起来像图像?只是想了解使用UIImage的扩展来旋转im的转换是如何工作的,但这只是暂时的,只是新的
public func imageRotatedByDegrees(degrees: CGFloat, flip: Bool) -> UIImage {
let radiansToDegrees: (CGFloat) -> CGFloat = {
return $0 * (180.0 / CGFloat(M_PI))
}
let degreesToRadians: (CGFloat) -> CGFloat = {
return $0 / 180.0 * CGFloat(M_PI)
}
// calculate the size of the rotated view's containing box for our drawing space
let rotatedViewBox = UIView(frame: CGRect(origin: CGPointZero, size: size))
let t = CGAffineTransformMakeRotation(degreesToRadians(degrees));
rotatedViewBox.transform = t
let rotatedSize = rotatedViewBox.frame.size
// Create the bitmap context
UIGraphicsBeginImageContext(rotatedSize)
let bitmap = UIGraphicsGetCurrentContext()
// Move the origin to the middle of the image so we will rotate and scale around the center.
CGContextTranslateCTM(bitmap, rotatedSize.width / 2.0, rotatedSize.height / 2.0);
// // Rotate the image context
CGContextRotateCTM(bitmap, degreesToRadians(degrees));
// Now, draw the rotated/scaled image into the context
var yFlip: CGFloat
if(flip){
yFlip = CGFloat(-1.0)
} else {
yFlip = CGFloat(1.0)
}
CGContextScaleCTM(bitmap, yFlip, -1.0)
CGContextDrawImage(bitmap, CGRectMake(-size.width / 2, -size.height / 2, size.width, size.height), CGImage)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
}

发布于 2015-11-26 13:18:35
您将需要使用核心动画与CATransform3D,并调整转换给一个深刻的印象。您要做的是将一个小的负值(-1/200是一个很好的起点)应用到转换矩阵的M34组件中。您可以对每个视图的层进行以太处理,或者在超级层上使用CATransformLayer,然后将其他图像添加为转换层的子层。
这是棘手的,挑剔的东西。我已经有一段时间没有搞砸了,所以我已经不记得细节了,但是这应该足够让你开始了。我建议在"iOS透视图“、"M34”和"CATransformLayer“中搜索更多内容。
https://stackoverflow.com/questions/33939555
复制相似问题