CGImage!数组没有填充

时间:2014-08-11 16:50:42

标签: ios arrays swift cgimage

这是一个模糊视图的类。我知道,iOS8有新的UIVisualEffectView,但我的目标是iOS7 我有一个数据没有填充CGImage的问题!对象。代码运行到func decreasinglyBlurredImages()结束,之后我收到此错误:

0x410fc4:  cmp    r6, #0x0  
0x410fc8:  beq    0x411004                  ; partial apply forwarder for     Swift._ContiguousArrayBuffer.(_asCocoaArray <A>(Swift._ContiguousArrayBuffer<A>) -> () ->   Swift._CocoaArray).(closure #1) with unmangled suffix "340" + 164  
0x410fcc:  ldr    r0, [r5]  
0x410fd0:  mov    r1, r4  
0x410fd4:  ldr    r2, [r0, #12]  
0x410fd8:  mov    r0, sp  
0x410fdc:  blx    r2  
0x410fe0:  ldr    r0, [r5]  
0x410fe4:  mov    r1, r4  
0x410fe8:  ldr    r2, [r0, #16]  
0x410fec:  mov    r0, r8  
0x410ff0:  blx    r2  
0x410ff4:  mov    r0, r6  
0x410ff8:  sub    sp, r7, #0x10  
0x410ffc:  ldr    r8, [sp], #4  
0x411000:  pop    {r4, r5, r6, r7, pc}  
0x411004:  trap                         Thread:3 EXE_BREAKPOINT ....  

在底部几乎是这个类的完整代码。我只是为了速度而试图预先填充数组并遇到了这个问题。有趣的是,如果我将optBlurredImagesForAnimation更改为UIImage并执行此操作:

func decreasinglyBlurredImages()->[UIImage]
{
    var images:[UIImage] = []

    for var i = numberOfImagesForAnimation; i > -1; i--
    {
        var blurredImageForAnimation:UIImage = UIImage(CGImage: blurImage(i))

        images.append(blurredImageForAnimation)
    }
    return images
}
一切正常!但是,我最终希望在CGImages中使用此CAKeyFrameAnimation数组,因此我需要CGImages

附加代码:

import UIKit
import Foundation
import QuartzCore

class AEBlurryImage: UIView {

    let imageToBlur:UIImage
    let blurFactor:NSNumber
    let numberOfImagesForAnimation = 10
    let buttonTitle:String?
    var optBlurredImagesForAnimation:[CGImage!]?


    init(frame: CGRect, image:UIImage, blurFactor:NSNumber)
    {
        imageToBlur = image

        if blurFactor == 0
        {
            self.blurFactor = self.numberOfImagesForAnimation
        }else
        {
        self.blurFactor = blurFactor
        }

        super.init(frame: frame)
    }


    func displayBlurredImage()
    {
        var blurredImage:CGImage!

        //get the blurred image and add it to the layer

        blurredImage = self.blurImage(nil)
        self.layer.contents = blurredImage

        if let blurredImagesForAnimation = optBlurredImagesForAnimation
        {
            return

        }else{

            let imageQueue:dispatch_queue_t = dispatch_queue_create("iQ", DISPATCH_QUEUE_SERIAL)

            dispatch_async(imageQueue){
                self.optBlurredImagesForAnimation = self.decreasinglyBlurredImages()
            }
        }
    }


    func blurImage(optionalFactor:NSNumber?)->CGImage!
    {
            var context:CIContext    = CIContext(options:nil)
            var image:CIImage        = CIImage(image:imageToBlur)
            var filterName:String?   = "CIGaussianBlur"
            var filter:CIFilter      = CIFilter(name:filterName)

            filter.setValue(image, forKey: kCIInputImageKey)

            //if optionalFactor is nil, just use the blurFactor
            if var factor = optionalFactor
            {
                filter.setValue(factor, forKey:kCIInputRadiusKey)
            }else
            {
                filter.setValue(blurFactor, forKey: kCIInputRadiusKey)
            }

            var result:CIImage       = filter.outputImage
            var rect:CGRect          = result.extent()
            var cgImage:CGImage!     = context.createCGImage(result, fromRect: rect)

            var blurredImage:CGImage! = cgImage

            return blurredImage
    }


    func decreasinglyBlurredImages()->[CGImage!]
    {
        var images:[CGImage!] = []

        for var i = numberOfImagesForAnimation; i > -1; i--
        {
            var blurredImageForAnimation:CGImage! = self.blurImage(i)

            images.append(blurredImageForAnimation)
        }
        return images
    }
}

1 个答案:

答案 0 :(得分:0)

我想我弄明白了我的问题。问题在于我用来开发的设备。该设备是安装了iOS7的iPhone 5,而不是iOS8。这段代码在模拟器中运行良好,而Rikkles所说的最终是为我解决的。再次感谢!