2016-08-09 1 views
0

私はUITabBarを持っています。各タブはタップすると色が変わります。アニメーションタブバーの色の変更

notSelectedColorとSelectedColorの間を0.5秒間アニメーション化したいのですが、どうすればいいですか?

が、私はそのような色で画像を再描画しています:

func imageWithColor(color: UIColor) -> UIImage { 
    UIGraphicsBeginImageContextWithOptions(size, false, scale) 

    let context = UIGraphicsGetCurrentContext() 
    CGContextTranslateCTM(context, 0.0, size.height) 
    CGContextScaleCTM(context, 1.0, -1.0) 
    CGContextSetBlendMode(context, CGBlendMode.Normal) 

    let rect = CGRect(origin: CGPointZero, size: size) 
    CGContextClipToMask(context, rect, CGImage) 
    color.setFill() 
    CGContextFillRect(context, rect) 

    let newImage = UIGraphicsGetImageFromCurrentImageContext() 
    return newImage 
} 

はあなたに感謝します!

+0

@ChiragPatelは、そこに任意の迅速な方法ではないでしょうか? –

答えて

2

は、次のコードによって、タブの色をアニメーション化することができます

let tabBar: UITabBar? = self.tabBarController?.tabBar 
     UIView.transitionWithView(tabBar!, duration: 1.0, options: [.BeginFromCurrentState, .TransitionCrossDissolve], animations: { 
      self.tabBarController?.tabBar.tintColor = UIColor.purpleColor() 
      }, completion: nil) 

は、私はまた、あなたのためのサンプルプロジェクトを行っています。 sample project hereをダウンロードしてください。私はちょうどたい色をアニメーション

enter image description here

+0

ありがとうございます!しかし、タップしたときに 'TabBar.image'と' TabBar.selectedImage'の間で消えてしまいたいです。これで私を助けてもらえますか?ありがとう! –