2016-08-09 4 views
0

У меня есть UITabBar, что каждая вкладка меняет свой цвет при нажатии.Анимация TabBar изменение цвета

Я хочу, чтобы он был анимированным (0,5 секунды между notSelectedColor и SelectedColor), как я могу это сделать?

Я перерисовывая изображение с цветом, как что:

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', когда он постучал. Не могли бы вы мне помочь? Благодаря! –

Смежные вопросы