快速将搜索栏放置在导航栏上

时间:2019-09-24 20:49:55

标签: swift uinavigationcontroller

enter image description here

在此图像中,导航栏上的搜索控制器。有一个显示用户名和个人资料图像的表格视图。当我尝试搜索某些东西时,它在导航栏和表格视图之间造成了缝隙。在图像中,您可以看到导航栏和用户表格视图之间的暗区。仅当我尝试搜索任何用户时,才会发生这种情况。如何摆脱这个问题。

我的代码是-

let fa = this.formBuilder.array([
  this.formBuilder.group({a: 0, b:0}),
  this.formBuilder.group({a: 0, b:0})
])
fa.setValue(data)

在我的聊天视图控制器中-

//MARK: Configure view controller

func configureViewController() {
    let storyBoard = UIStoryboard(name: "Main", bundle: nil)

    // Create instance for Matchess view with storybaordId

    let matches = storyBoard.instantiateViewController(withIdentifier: "MatchesViewController") as? MatchesViewController
    let matchesProfileVC = configureNavController(unselectedImage: UIImage(named: "logo_BLK.png")!, selectedImage:UIImage(named: "logo focus.png")!, rootViewController: matches!)

    // Create instance for liks view with storybaordId

    let likes = storyBoard.instantiateViewController(withIdentifier: "LikesViewController") as? LikesViewController
    let likesVC = configureNavController(unselectedImage: UIImage(named: "heart_BLK.png")!, selectedImage:UIImage(named: "heart Focus.png")!, rootViewController: likes!)

     // Create instance for user chat view with storybaordId

    let chat = storyBoard.instantiateViewController(withIdentifier: "UserChatViewController") as? UserChatViewController

    let chatVC = configureNavController(unselectedImage: UIImage(named: "Chat.png")!, selectedImage:UIImage(named: "chat focus.png")!, rootViewController: chat!)

    // Create instance for profile view with storybaordId
    let profile = storyBoard.instantiateViewController(withIdentifier: "ProfileViewController") as? ProfileViewController



    let profileVC = configureNavController(unselectedImage: UIImage(named: "Profile_BLK.png")!, selectedImage:UIImage(named: "profile focus .png")!, rootViewController: profile!)


    // Add all the view instances to the tabbar

    viewControllers = [matchesProfileVC, likesVC, chatVC, profileVC ]

}

 //    Configuration navigation with tabbar selecte and unselected image

func configureNavController(unselectedImage: UIImage, selectedImage: UIImage, rootViewController: UIViewController) -> UINavigationController {
    let navControler = UINavigationController(rootViewController: rootViewController)

    navControler.tabBarItem.image = unselectedImage.withRenderingMode(.alwaysOriginal)
    navControler.tabBarItem.selectedImage = selectedImage.withRenderingMode(.alwaysOriginal)

    navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)


    return navControler
}
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {

    guard let fromView = selectedViewController?.view, let toView = viewController.view else {
        return false // Make sure you want this as false
    }

    if fromView != toView {

        //Animation added to tabbar when tabbar icon selected
        let bounceAnimation = CAKeyframeAnimation(keyPath: "transform.scale")
                bounceAnimation.values = [1.0 ,1.4, 0.9, 1.15, 0.95, 1.02, 1.0]
        bounceAnimation.duration = TimeInterval(0.3)
        bounceAnimation.calculationMode = CAAnimationCalculationMode.cubic
        self.tabBar.layer.add(bounceAnimation, forKey: "bounceAnimation")


        //View transition  when tabbar icon selected
        UIView.transition(from: fromView, to: toView, duration: 0.3, options: [.transitionCrossDissolve], completion: nil)
    }

    return true
}

0 个答案:

没有答案