今回の内容

コードと簡単解説
-
Main.storyboardで
TabBarController
を作成します。 -
Main.storyboardでTabBarItemの画像などを設定しておきます。
全てのコード
-
tabBar.unselectedItemTintColor
は未選択アイコンの色を設定しています。 -
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {}
内で、アイコン画像がUIImage(systemName: "arrow.up.and.down.circle")
の時はtabBarを画面から見えない位置まで下げます。そして、2秒後に元の位置に戻る様にしています。
TabBarController
import UIKit
class TabViewController: UITabBarController,UITabBarControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
tabBarController?.delegate = self
tabBar.barTintColor = .systemIndigo
tabBar.unselectedItemTintColor = .white
tabBar.tintColor = .systemGreen
tabBar.layer.borderWidth = 1.0
tabBar.layer.borderColor = UIColor.systemGreen.cgColor
tabBar.layer.cornerRadius = 45.0
tabBar.layer.masksToBounds = true
}
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
if item.selectedImage == UIImage(systemName: "arrow.up.and.down.circle") {
UITabBar.animate(withDuration: 0.5, delay: 0, options: .curveEaseInOut, animations: {self.tabBar.frame.origin.y = self.tabBar.frame.origin.y + self.tabBar.frame.size.height}, completion: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
UITabBar.animate(withDuration: 0.5, delay: 0, options: .curveEaseInOut, animations: {self.tabBar.frame.origin.y = self.tabBar.frame.origin.y - self.tabBar.frame.size.height}, completion: nil)
}
}
}
}
終わり
ご指摘、ご質問などありましたら、コメントまでお願い致します。