Customizing UITabBarController with Animated UITabBarItem in Swift

In iOS development, UITabBarController is a key component for displaying multiple view controllers with switchable tabs. This example demonstrates how to create a custom UITabBarController in Swift and add custom animations to UITabBarItem to enhance user experience and visual appeal. To set up UITabBarController, initialize it and add view controllers to its viewControllers property:

let tabBarController = UITabBarController()
let viewController1 = UIViewController()
let viewController2 = UIViewController()
tabBarController.viewControllers = [viewController1, viewController2]

Customize UITabBarItem by setting title, image, and selectedImage:

viewController1.tabBarItem = UITabBarItem(title: "Home", image: UIImage(named: "home_unselected"), selectedImage: UIImage(named: "home_selected"))
viewController2.tabBarItem = UITabBarItem(title: "Profile", image: UIImage(named: "profile_unselected"), selectedImage: UIImage(named: "profile_selected"))

To add custom click animations, override the tabBar(_:didSelect:) method in a subclass of UITabBarController:

class CustomTabBarController: UITabBarController {
    override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
        let currentIndex = tabBar.items?.firstIndex(of: item)
        UIView.animate(withDuration: 0.3, animations: {
            tabBar.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
        }) { (finished) in
            UIView.animate(withDuration: 0.3) {
                tabBar.transform = .identity
            }
        }
    }
}

To enhance flexibility, encapsulate animation logic in a method that can be reused. Additional customization options, such as animation types and durations, can be included as needed. Be mindful of other details like updating view states of child controllers and adapting the UITabBar appearance based on user preferences, which can be managed by implementing additional UITabBarControllerDelegate methods. Customizing UITabBarController allows for greater application personalization and improved user experience.

zip
UITabbarController.zip 预估大小:152个文件
file
exclude 40B
file
9df098625f128382071ae9707970fe8a086464 95B
file
42a578ea3431797e7c8ad56984df744a95e7f7 245B
file
632d3c82be00c5309b1571b9a32ecf4acf9ed2 102B
file
13ea0f5223a4be007cfdfe404ac8d80132e24f 10KB
file
294bd59410b262d373241b5c7c62ccb819bf11 1KB
file
dc400a9c09794e65752618607ebdd5c2b369bb 7KB
file
80b4d06b10ccfe7512f99fa0a10ab2a4f4df88 625B
file
c2fbf1ae7abb91d68a852b147c3c55356cd2ef 1KB
file
33c614c00ad022835a76bc50de40849757f9b8 1KB
file
683f33a591bbea03817e07894b45464da31105 5KB
file
e6a35b5b6613750c96f9b3a121ad9dd6c84b80 1KB
file
bc33c770ab1d198280c3c02f3eb1dc0b88f558 51B
file
bc08aea21292e8fbca2ebefb981a79cd1d244f 646B
file
4a164c918651cdd1e11dca5cc62c333f097601 65B
file
c8b620e3ab213298b677fe6564f54e86be4c53 58B
file
b0ac5880cb5d5f6d6e669261bd0c2f7755e948 165B
file
5e9329f3767a7c1dd66294b8025bf81dee7d2c 781B
file
5010843634a55cad501346bffbba796ec4cb38 131B
file
947b9d4b3a27d43e0cc19a2f83ff16e0214c2a 1KB
file
d5e421f048fa8da62978d39f82da82d295ade3 9KB
file
288b2a21771c77d491e540efa36e92aa5bfa12 80B
file
2711f200d37da2ea2aede651fc54c614738714 165B
file
6686e05bad7b2db9bdd35d77cb6f85ed2b50f0 165B
file
2d25aca775cdf4ffa677d1911ea0e3ccbfea07 2KB
file
7cb822e4711a6e61b9354faaab370b61c5c936 159B
file
57f7c5dc05bb5b88dbf97755afc4031fd5357f 162B
file
dd28bb49026990cde5ccc2a4ddb5ec63da8d89 2KB
file
750b3b8a64db5c755678db75496d3254ea2694 1KB
file
95959e7e7bec30af600eab012ba8ee3155e2b1 105B
file
4388b5c945893a6133c0d1156495ce21112736 239B
file
26618a58e6bd6a621933e110b67bf603585622 156B
file
b3d1b7d75df008300b0c9855c43e1c95bd4086 4KB
file
574c99bd1b061cd15382c37c995e2c3002ec70 974B
file
a763858ecdbea5c897a9fd8fa2225d7223d2ad 749B
file
de2f734fa914994a1be908d1633ae24633ae88 2KB
file
14bf64d45984b9bf4bc6460591d3781fb65ed8 16KB
file
5c0d80de1751f48e306849f4dd798501c3ee5e 278B
file
331fa2f9d5dde5e77b6f3167c6e7a7cada8de6 402B
file
ee0c1e69110a71022ac49c9a193db4b6d9dee0 11KB
file
ee0a7ba48632b0dee2e4ffa5f36b0510332bb9 151B
file
44b4bef835661f7b8c3806081e7e03167534aa 171B
file
8e3ef31811bc8f70f775fd7f50a4e005878360 165B
file
53e858ea8137655037f90982f2b79124c57519 177B
file
fc3bc51274a8bc0c428e8b9f1482935836702c 729B
file
3695e660a7a55fbe122f03cd86396545ad35be 125B
file
21b9bb1a35f5de270a41afa01305478221ae32 253B
file
35e5c67a08ee6e46f9aebc767d7e7e73eccc71 1KB
file
8d44963998c6c9953adbad323364715e6ae490 158B
file
43b7901a0d968058dbb4a2ff4630768294665d 764B
file
54fabe24a69230948caa7d547b6e181a8b5ddd 2KB
file
0e444381b8da0ce57e4d54f3d51bbdc82a64e9 155B
file
538d9d01423f24f4f2172237292ee859ada268 1KB
file
3483c0d2ba679db55e66b185bfd79b44b0cf07 715B
file
883bcd1a2c179f1452cbf5e30bba39163daaab 67B
file
f1da257c971a73dea2073fc71bf69e4a065c31 1KB
file
3cc9b8ba4e4ae5c6df5ed5e3f199668b7fead0 68B
file
f4c6d5852faa80d14f046bbc6c2c1d0e28de16 2KB
file
ec612ee8c9324d29ccbf4b24d6f19dfb3888d8 402B
file
fbb51b81eb59ae334366160a4596ae44aafde5 221B
file
7d0c4476211f740d057da2e6be7fef16990634 20KB
file
8d5b4bdb686494e65015e2458d1fa5fc2c95ab 2KB
file
d981003d68d0546c4804ac2ff47dd97c6e7921 206B
file
8c7aa1363fee92cfd8cfa4819ef314a9e1f2c7 2KB
file
5c3d71ebab8dcdb26de83e6e031cb27671bd30 154B
file
391ff2eaf973e6c02a93eb9c6ab549f18bfa48 2KB
file
6222842a78f586745473e12457916c372d4a17 167B
file
b4f948fbede32277bfe3febdd996ecf25054a5 652B
file
4bfa5ef938026844a9d03a0f3c26d6bc9d2c25 159B
file
69defd66cacdb95a6bf5dc9f8a481757485b55 8KB
file
ab9ea78b169fbbe27c6f783447765848f8097a 2KB
file
de513d1e8557b2eea6776cf134531abd08d19f 1KB
file
cc241f8df6216afa5bab17f0b92c55931052ea 130B
file
40e76a4ac6805ba16c7d3780b8964433adecb1 1KB
file
52703d6cb8f4f3166a51b0e9e27e8559dd4d03 2KB
file
cbb7700047f731e5998e69f0707ad1cc7a3ed9 155B
file
81c6b9bef9ea0b4acbf240ab8bf1ab4f9d541c 164B
file
7d7cc459f0658f159c91c857af92ad95edf8e7 1KB
file
c00596a7fca3f3d4bdd64053b69d86745f9e10 66B
file
9fc883fc465626c2d664ee9a5617dd4e29c91a 159B
file
15f262b4ad3cf831c515ad598a2c6af15ca035 1KB
file
08caac7f5067c86bff7f060a74ce7faf6b78f2 1KB
file
0959cb3fd9583b3d8e8706fe66ddb9cb240a4f 3KB
file
0a56f0238cad57a72e840bdeb9fdaea56de29c 1KB
file
04ee41d564842f4211cfc260586f613024dd73 13KB
file
e315e680270924a84b19ca4df5f615f1f57bd2 56B
file
5f044964241be0ff80409ef32c5291bb8d5572 158B
file
fdca5cb1331f19e7ddb33b695e2164470d225a 3KB
file
18e1bb87e9af28ef364fb34ad58bc1cdec1b1a 2KB
file
a70031287567d78c8182060b37b9f74b4ea50a 155B
file
HEAD 23B
file
description 73B
file
config 137B
file
index 3KB
file
master 41B
file
COMMIT_EDITMSG 15B
file
README.sample 177B
file
HEAD 153B
file
master 153B
file
Manifest.lock 77B
file
project.pbxproj 16KB
file
xcschememanagement.plist 344B
file
Pods-Test.xcscheme 2KB
file
xcschememanagement.plist 417B
file
Pods-Test-frameworks-Debug-input-files.xcfilelist 115B
file
Pods-Test-umbrella.h 310B
file
Pods-Test-dummy.m 122B
file
Pods-Test.modulemap 108B
file
Pods-Test-acknowledgements.markdown 133B
file
Pods-Test.release.xcconfig 294B
file
Pods-Test-Info.plist 828B
file
Pods-Test-acknowledgements.plist 805B
file
Pods-Test-frameworks-Release-input-files.xcfilelist 115B
file
Pods-Test-frameworks.sh 9KB
file
Pods-Test-frameworks-Release-output-files.xcfilelist 63B
file
Pods-Test.debug.xcconfig 294B
file
Pods-Test-frameworks-Debug-output-files.xcfilelist 63B
file
.DS_Store 6KB
file
IDEWorkspaceChecks.plist 238B
file
contents.xcworkspacedata 149B
file
UserInterfaceState.xcuserstate 25KB
file
project.pbxproj 19KB
file
xcschememanagement.plist 339B
file
xcschememanagement.plist 339B
file
IDEWorkspaceChecks.plist 238B
file
contents.xcworkspacedata 222B
file
UserInterfaceState.xcuserstate 24KB
file
UserInterfaceState.xcuserstate 49KB
file
Breakpoints_v2.xcbkptlist 140B
file
CustomTabBarView.swift 4KB
file
CustomTabBarView的副本.swift 8KB
file
TestTableViewCell.xib 3KB
file
SearchBarController.swift 881B
file
DataManage.swift 301B
file
SearchTwoController.swift 940B
file
ViewController.swift 3KB
file
CustomBarView.swift 3KB
file
Info.plist 1KB
file
TabBarController.swift 7KB
file
UIColorExtension.swift 2KB
file
CustomSearchBarView.swift 6KB
file
LaunchScreen.storyboard 2KB
file
Main.storyboard 3KB
file
TestTableViewCell.swift 479B
file
AppDelegate.swift 1KB
file
.DS_Store 6KB
file
Contents.json 63B
file
Contents.json 2KB
file
.DS_Store 6KB
file
Contents.json 63B
file
Podfile.lock 77B
file
Podfile 256B
...
zip 文件大小:396.98KB