0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

UITabBarController カスタム 復習

Posted at

今回の内容

3F023247-7BA7-4C4C-A930-3F264ADFDE89_1_201_a.jpeg

コードと簡単解説

  • 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)

            }

        }

      }
      
}

終わり

ご指摘、ご質問などありましたら、コメントまでお願い致します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?