Swift自定义iOS中的TabBarController并为其添加动画

2020-01-08 23:07:41于丽

        // 去掉buttond的高光效果
        button.adjustsImageWhenHighlighted = false

        backgroundView.addSubview(button)
    }              
}

 


添加onClick方法,动画效果也在这里面实现:

 

 

复制代码

 

func onClick(button: UIButton) {
    // 将上个选中俺就设置为为选中
    self.currentSelectedButton.selected = false
    // 当前按钮设置为选中
    button.selected = true

    self.currentSelectedButton = button

    let x = CGFloat(button.tag) + 0.5

    // 为TabBarItem的背景添加动画
    UIView.animateWithDuration(0.4, delay: 0.0, usingSpringWithDamping: 0.7, initialSpringVelocity: 10.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in

        self.selectionIndicatorImageView.center.x = self.itemWidth * x

        }, completion: nil)

    self.selectedIndex = button.tag
}

 


最终效果如下:

 

Swift,iOS,TabBarController



注:相关教程知识阅读请移步到swift教程频道。