Swift:在集合视图中延迟加载动画?

时间:2017-04-20 12:54:47

标签: ios swift swift3 uicollectionview imessage-extension

我还没有在其他任何地方看过这个主题 - 我已经构建了一个iMessage应用程序,它使用collecitonview来保存一堆MSStickerViews。这些贴纸是动画的。

我的问题是,虽然应用程序本身在您首次打开时似乎加载,但是在能够触摸贴纸/与应用程序交互之前以及MSStickers开始制作动画之前会有明显的延迟。我不确定这是否是被调用的函数的顺序,但我找不到改进/修复它的方法。

我的MSStickers将添加到集合视图单元格中:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

        // get a reference to our storyboard cell
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "stickerCell", for: indexPath as IndexPath) as! StickerCollectionViewCell

然后在单独的Cell类中添加贴纸视图并将其设置为.startAnimating()

延迟大约5-6秒。我怎样才能减少这个?这可能吗?

动画/贴纸代码:

 for (animal, atlas) in animalsAnim {
            animalsAnim[animal] = getImagesForAnimals(animal: animal, allSticks: allStickers)
            addSticker(images: animalsAnim[animal]!, name: animal)
        }

func addSticker(images: [UIImage], name: String)
    {
        let sticker: MSSticker
        do {
            try sticker=MSSticker(images: images, format: .apng, frameDelay: 0.95/14.0, numberOfLoops: 0, localizedDescription: name)
        }catch MSStickerAnimationInputError.InvalidDimensions {
            fatalError("ERROR: Dimens")
        }catch MSStickerAnimationInputError.InvalidStickerFileSize {
           fatalError("ERROR: Size")
        } catch { fatalError("other error:\(error)") }

        var stickerSize = CGSize()

        if (UIDevice.current.iPhone5orBefore)
        {

            stickerSize = CGSize(width: view.bounds.width*0.38, height: view.bounds.width*0.38)
        }
        else {
            stickerSize = CGSize(width: view.bounds.width*0.4, height: view.bounds.width*0.4)
        }

        let stickerView = InstrumentedStickerView(frame: CGRect(origin: CGPoint(x: 0,y :0), size: stickerSize))

        stickerView.sticker = sticker
        stickerView.delegate = self

        stickerPack.append(stickerView)
    }

然后添加贴纸视图并在单独的单元类中开始制作动画。

0 个答案:

没有答案
相关问题