gpt4 book ai didi

ios - 导航栏后面的搜索栏

转载 作者:行者123 更新时间:2023-11-29 01:10:26 25 4
gpt4 key购买 nike

给定 3 个 Controller :A、B、CA 有一个隐藏的导航栏。通过 StoryboardReference 调用 Controller B。 Controller B 在 vi​​ewDidLoad 上显示导航栏。它有一个搜索栏和一个collectionView。请参阅我的 Storyboard的屏幕截图 A。如果单击单元格,则调用 Controller C。

问题:如果 A 调用 B,则搜索栏位于导航栏后面(屏幕截图 B)。它出现在从 C 到 B 的过渡中(屏幕截图 C)。

导航栏已经是半透明的。有什么想法吗?

编辑

我意识到我的动画过渡导致了我的问题。

也许你能发现错误?

class ZoomInCircleViewTransition: NSObject, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate {

var transitionContext: UIViewControllerContextTransitioning?

func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
return 0.6
}

func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
self.transitionContext = transitionContext

guard let toViewController: UIViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey) else {
return
}

guard let fromViewController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey) else { return
}

guard let fromViewTransitionFromView = fromViewController as? TransitionFromViewProtocol else {
return
}

let imageViewSnapshot = fromViewTransitionFromView.getViewForTransition()

let endFrame = CGRectMake(-CGRectGetWidth(toViewController.view.frame)/2, -CGRectGetHeight(toViewController.view.frame)/2, CGRectGetWidth(toViewController.view.frame)*2, CGRectGetHeight(toViewController.view.frame)*2)

if let containerView = transitionContext.containerView(){
containerView.addSubview(fromViewController.view)
containerView.addSubview(toViewController.view)
containerView.addSubview(imageViewSnapshot)
}


let maskPath = UIBezierPath(ovalInRect: imageViewSnapshot.frame)
let maskLayer = CAShapeLayer()
maskLayer.frame = toViewController.view.frame
maskLayer.path = maskPath.CGPath
toViewController.view.layer.mask = maskLayer

let quadraticEndFrame = CGRect(x: endFrame.origin.x - (endFrame.height - endFrame.width)/2, y: endFrame.origin.y, width: endFrame.height, height: endFrame.height)
let bigCirclePath = UIBezierPath(ovalInRect: quadraticEndFrame)

let pathAnimation = CABasicAnimation(keyPath: "path")
pathAnimation.delegate = self
pathAnimation.fromValue = maskPath.CGPath
pathAnimation.toValue = bigCirclePath
pathAnimation.duration = transitionDuration(transitionContext)
maskLayer.path = bigCirclePath.CGPath
maskLayer.addAnimation(pathAnimation, forKey: "pathAnimation")


let hideImageViewAnimation = {
imageViewSnapshot.alpha = 0.0
}

UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: hideImageViewAnimation) { (completed) -> Void in
}

let scaleImageViewAnimation = {
imageViewSnapshot.frame = quadraticEndFrame
}
UIView.animateWithDuration(transitionDuration(transitionContext), delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: scaleImageViewAnimation) { (completed) -> Void in
// After the complete animations have endet
imageViewSnapshot.removeFromSuperview()
toViewController.view.layer.mask = nil
}
}

override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let transitionContext = self.transitionContext {
transitionContext.completeTransition(!transitionContext.transitionWasCancelled())
}
}

// MARK: UIViewControllerTransitioningDelegate protocol methods

// return the animataor when presenting a viewcontroller
func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return self
}

// return the animator used when dismissing from a viewcontroller
func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return self
}
}

最佳答案

我相信我在我的应用程序中遇到了一些类似的问题,但由于您无法控制的所有事情而遇到了困难。我的解决方案是在导航栏中放置一个搜索图标,然后让搜索 Controller 在导航栏上向下滑动,使其远离表格/ ScrollView 。这是我的实现(应该是完整的)

import UIKit

class tvc: UITableViewController, UISearchBarDelegate, UISearchControllerDelegate {

var searchController:UISearchController!

@IBAction func startSearch() {
self.navigationController?.presentViewController(self.searchController, animated: true, completion: {})
}

override func viewDidDisappear(animated: Bool) {
cancelSearch(self)
}

override func viewDidLoad() {
super.viewDidLoad()

searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.delegate = self
searchController.hidesNavigationBarDuringPresentation = false
searchController.loadViewIfNeeded() /* Fixes bug in iOS http://stackoverflow.com/questions/32675001/uisearchcontroller-warning-attempting-to-load-the-view-of-a-view-controller */
definesPresentationContext = true
tableView.sectionIndexBackgroundColor = UIColor.clearColor()
tableView.sectionIndexTrackingBackgroundColor = UIColor.clearColor()
}

extension tvc: UISearchResultsUpdating {
// MARK: - UISearchResultsUpdating Delegate
func updateSearchResultsForSearchController(searchController: UISearchController) {
filterContentForSearchText(searchController.searchBar.text!)
}
}

func cancelSearch(sender: AnyObject?) {
if sender!.searchController.active == true {
sender?.searchController.resignFirstResponder()
sender!.navigationController!!.dismissViewControllerAnimated(false, completion: {})
sender!.searchController.searchBar.text = ""
sender!.searchController.active = false
}
}

关于ios - 导航栏后面的搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35826739/

25 4 0