Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了How to create tabbar with ESTabBarController in swift 3.0大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

How to create tabbar with ESTabBarController in swift 3.0 First Install CocoaPods Open terminal and cd ~ to your project directory Run the command - pod init Your podfile should be use with - pod "EST

How to create tabbar with ESTabBarController in swift 3.0

First Install CocoaPods

    @H_419_5@Open terminal and cd ~ to your project directory @H_419_5@Run the command - pod init @H_419_5@Your podfile should be use with - pod "ESTabBarController-swift" and save it @H_419_5@And install it with command pod install

Open project file of .xcworkspace extension

    @H_419_5@In project we need to add Content all swift class and pop.framework @H_419_5@Don't add pop.framework using add File to. you must be add from Framework and add Others. @H_419_5@In Content folder's all file import ESTabBarController_swift

StoryBord stuff

Add navigation Controller ane also add ExampleNavigationController from the example code of EST demo. (You can add your own too) but make sure you set its Class of navigation custom swift class.
Code stuff at AppDelegate.swift

You need to do following code AppDelegate.swift

//
//  AppDelegate.swift
//  DNApp
//
//  Created by 雷神 on 2017/9/6.
//  Copyright © 2017年 aider.cc. All rights reserved.
//

import UIKit
import CoreData
import ESTabBarController_swift

@UIApplicationMain
class AppDelegate: UIResponder,UIApplicationDelegate,UITabBarControllerDelegate {

    
    var window: UIWindow?
    
    
    func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        let tabBarController = ESTabBarController()
        tabBarController.delegate = self
        tabBarController.title = "Irregularity"
        tabBarController.tabBar.shadowImage = UIImage(named: "transparent")
        tabBarController.tabBar.BACkgroundImage = UIImage(named: "BACkground_dark")
        tabBarController.shouldHijackHandler = {
            tabbarController,viewController,index in
            if index == 2 {
                return true
            }
            return false
        }
        tabBarController.didHijackHandler = {
            [weak tabBarController] tabbarController,index in
            
            DispatchQueue.main.asyncAfter(deadline: .Now() + 0.2) {
                let alertController = UIAlertController.init(title: nil,message: nil,preferredStyle: .actionSheet)
                let takePhotoAction = UIAlertAction(title: "Take a photo",style: .default,handler: nil)
                alertController.addAction(takePhotoAction)
                let SELEctFromAlbumAction = UIAlertAction(title: "SELEct from album",handler: nil)
                alertController.addAction(SELEctFromAlbumAction)
                let cancelAction = UIAlertAction(title: "Cancel",style: .cancel,handler: nil)
                alertController.addAction(cancelAction)
                tabBarController?.present(alertController,animated: true,completion: nil)
            }
        }

        let v1 = ExampleViewController()
        let v2 = ExampleViewController()
        let v3 = ExampleViewController()
        let v4 = ExampleViewController()
        let v5 = ExampleViewController()
        v1.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(),title: "Home",image: UIImage(named: "home"),SELEctedImage: UIImage(named: "home_1"))
        v2.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(),title: "Find",image: UIImage(named: "find"),SELEctedImage: UIImage(named: "find_1"))
        v3.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(),title: "Photo",image: UIImage(named: "photo"),SELEctedImage: UIImage(named: "photo_1"))
        v4.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(),title: "Favor",image: UIImage(named: "favor"),SELEctedImage: UIImage(named: "favor_1"))
        v5.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(),title: "Me",image: UIImage(named: "me"),SELEctedImage: UIImage(named: "me_1"))
        
        tabBarController.viewControllers = [v1,v2,v3,v4,v5]

        let navigationController = ExampleNavigationController.init(rootViewController: tabBarController)
        tabBarController.title = "Example"
        
        
        self.window?.rootViewController = navigationController

        return true
    }
    
    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS messagE) or when the user quits the application and it begins the transition to the BACkground state.
        // Use this method to pause ongoing tasks,disable timers,and invalidate graphics rendering callBACks. Games should use this method to pause the game.
    }
    
    func applicationDidEnterBACkground(_ application: UIApplication) {
        // Use this method to release shared resources,save user data,invalidate timers,and store enough application state information to restore your application to its current state in case @R_944_8913@ terminated later.
        // If your application supports BACkground execution,this method is called instead of applicationWillTerminate: when the user quits.
    }
    
    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the BACkground to the active state; here you can undo many of the changes made on entering the BACkground.
    }
    
    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was prevIoUsly in the BACkground,optionally refresh the user interface.
    }
    
    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBACkground:.
        // Saves changes in the application's managed object context before the application terminates.
        self.saveContext()
    }
    
    // MARK: - Core Data stack
    
    lazy var persistentContainer: NSPersistentContainer = {
        /*
         The persistent container for the application. This implementation
         creates and returns a container,having loaded the store for the
         application to it. This property is optional since there are legitimate
         error conditions that Could cause the creation of the store to fail.
         */
        let container = NSPersistentContainer(name: "DNApp")
        container.loadPersistentStores(completionHandler: { (storeDescription,error) in
            if let error = error as NSError? {
                // replace this implementation with code to handle the error appropriately.
                // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application,although it may be useful during development.
                
                /*
                 Typical reasons for an error here include:
                 * The parent directory does not exist,cAnnot be created,or disallows wriTing.
                 * The persistent store is not accessible,due to permissions or data protection when the device is locked.
                 * The device is out of space.
                 * The store Could not be migrated to the current model version.
                 check the error message to determine what the actual problem was.
                 */
                fatalError("Unresolved error \(error),\(error.userInfo)")
            }
        })
        return container
    }()
    
    // MARK: - Core Data Saving support
    
    func saveContext () {
        let context = persistentContainer.viewContext
        if context.hasChanges {
            do {
                try context.save()
            } catch {
                // replace this implementation with code to handle the error appropriately.
                // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application,although it may be useful during development.
                let nserror = error as NSError
                fatalError("Unresolved error \(nserror),\(nserror.userInfo)")
            }
        }
    }
    
}

大佬总结

以上是大佬教程为你收集整理的How to create tabbar with ESTabBarController in swift 3.0全部内容,希望文章能够帮你解决How to create tabbar with ESTabBarController in swift 3.0所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。