2015-11-26 48 views
0

如何將圖像轉換爲圖像中的圖像? 只是想達到這種轉變是如何工作的 旋轉使用的UIImage的一種推廣IM,但多數民衆贊成全部得到了現在,只要新的迅速UIImage 3Transform swift

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 
} 

dashboard

回答

0

您將需要使用的Core Animation與CATransform3D,並調整轉換給深度的印象。你所做的是將一個小的負值(-1/200是一個好的起點)應用到變換矩陣的M34分量。您可以將它視爲您每個視圖的圖層,或者在超級圖層上使用CATransformLayer,然後將其他圖像添加爲變換圖層的子圖層。

這是棘手的,挑剔的東西。我一段時間沒有搞砸了,所以我不再記得細節,但那應該足以讓你開始。我建議搜索「iOS透視圖」,「M34」和「CATransformLayer」以瞭解更多信息。

+0

順便說一句,有一個非常酷的第三方庫稱爲iCarousel,你可能可以用它來創建你以後的效果。我不確定它可以做這樣的矩陣。您可能必須將3個傳送帶疊在一起。 –

+0

謝謝你們! –