Swift我的闪屏的颜色变为黑色

时间:2018-06-01 09:39:50

标签: swift animation splash-screen

我已经在我的应用程序图标(这是一个红色图标)上放了一个像启动画面的Twitter:

import UIKit
import QuartzCore

class SplachScreenAnimationViewController: UIViewController,CAAnimationDelegate {

    // MARK: - Variable
    var mask:CALayer?

    // MARK: - Outlets
    @IBOutlet var imageView:UIImageView!

    // MARK: - Life cycle
    override func viewDidLoad() {

        self.mask = CALayer()
        self.mask!.contents = UIImage(named:"MyAppIcon")!.cgImage
        self.mask!.contentsGravity = kCAGravityResizeAspect
        self.mask!.bounds = CGRect(x: 0, y: 0, width: 100, height: 100)
        self.mask!.anchorPoint = CGPoint(x: 0.5, y: 0.5)
        self.mask!.position = CGPoint(x: self.view.frame.size.width/2, y: self.view.frame.size.height/2)

        //add logo as mask to view
        self.imageView.layer.mask = mask

        self.view.backgroundColor = UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 1.0)
        self.animate()

    }
    func animate(){


        let keyFrameAnimation = CAKeyframeAnimation(keyPath: "bounds")
        keyFrameAnimation.delegate = self
        keyFrameAnimation.duration = 1
        keyFrameAnimation.beginTime = CACurrentMediaTime() + 1 //Add delay 1 secund

        //start animation
        let initialBounds = NSValue(cgRect: self.mask!.bounds);

        //bounce/zooming effect 
        let middleBounds = NSValue(cgRect: CGRect(x: 0, y: 0, width: 90, height: 90))

        //final/zooming effect
        let finalBounds = NSValue(cgRect: CGRect(x: 0, y: 0, width: 1500, height: 1500))

        //add NSValues and keytimes
        keyFrameAnimation.values = [initialBounds,middleBounds,finalBounds];
        keyFrameAnimation.keyTimes = [0, 0.3, 1]

        //animation timing funtions
        keyFrameAnimation.timingFunctions = [CAMediaTimingFunction(name:kCAMediaTimingFunctionEaseInEaseOut),CAMediaTimingFunction(name:kCAMediaTimingFunctionEaseIn)]

        //add animations
        self.mask?.add(keyFrameAnimation, forKey: "bounds")

    }

    func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
            //remove mask when animation completes
        self.imageView.layer.mask = nil
    }
    }

在我的资产中,我可以清楚地看到我的应用程序图标为红色。 当我启动应用程序时,我可以看到我的图标执行启动画面,但应用程序徽标是黑色(而不是红色)

任何人都有想法解决这个问题吗?

谢谢!

0 个答案:

没有答案