导航控制器在推送到View Controller之前延迟

时间:2018-11-06 02:31:32

标签: ios swift xcode swift3 uinavigationcontroller

我有一个View Controller A,它具有带有项目列表的集合视图。我必须推送到另一个View controller B。

当我在“收藏夹视图”中选择一个项目时,我希望进行此推送。但是,推送是在我想避免的短暂延迟之后发生的。

didSelect Item方法之后,我只有几行代码,在View Controller B的NavigationController's navigation Bar setupCollectionView setup方法中,还有View Did loadView Will Appear

我尝试在CollectionView Did Select之后删除代码,只是为了检查这是否引起延迟,但动画仍然很慢。

查看控制器A代码。

DispatchQueue.global(qos: .background).async {
        DispatchQueue.main.async {
            //write your code here
            var dict = projectsArray[indexPath.row - 1] as! [String:Any]

        guard let id = dict["_id"] as? NSNumber else{return }
        var canvasIds = NSArray()
        if let idsAll = projectCanvasIds.object(forKey: id.stringValue) as? NSArray{
            canvasIds = idsAll
        }
        dict["CanvasIds"] = canvasIds
        let dict2 = dict as NSDictionary
        IndexContentsModel.projectSlectedCanvasIds = dict2.mutableCopy() as! NSMutableDictionary
        let vc = IndexCanvasViewController(nibName: "IndexCanvasViewController", bundle: nil)

        self.navigationController?.pushViewController(vc, animated: true)

        }
    }

查看控制器B代码

查看是否加载了CollectionViewInit()SetUI()

func collectionViewinit(){
    let nib = UINib(nibName: "TopCanvasesCollectionViewCell", bundle: nil)
    self.collectionView.register(nib, forCellWithReuseIdentifier: "topCanvasCell")

    collectionView.register(UINib(nibName: "CanvasViewCollectionReusableView3", bundle: nil), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "canvasHeaderView")
}

func setUI(){


    self.navigationController?.navigationItem.hidesBackButton = true
    self.navigationController?.navigationBar.clipsToBounds = true
    self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
    self.navigationController?.navigationBar.shadowImage = UIImage()

    let imgView = UIImageView(frame: CGRect(x: 0, y: 0, width: 40, height: 40))

    let hostStr = host
    let userinfo = UserInfo.shared()
    if let photo = userinfo?.dicJSON.object(forKey: "photo") as? String{
        let profile = host + photo
        imgView.sd_setImage(with: URL(string: profile), completed: nil)
    }else{
        imgView.image = UIImage(named: "test_Profile")
    }
    let button = UIButton()

    button.addTarget(self, action:#selector(profileViewButtonPressed(_:)), for: UIControlEvents.touchUpInside)
    button.frame = CGRect(x: 0, y: 0, width: 36, height: 36)// CGRectMake(0, 0, 36, 36)
    button.layer.cornerRadius = button.frame.width / 2
    button.layer.masksToBounds = true
    button.setImage(imgView.image, for: UIControlState.normal)
    //        let profileButton = UIBarButtonItem(customView: button)



    let searchImage    = UIImage(named: "Search_Icon3")!
    let notificationImage  = UIImage(named: "Notification_Icon3")!
    let profileImage  = UIImage(named: "test_Profile")!
    let backImage  = UIImage(named: "Back_Icon3")!

    let searchButton   = UIBarButtonItem(image: searchImage,  style: .plain, target: self, action: #selector(searchViewButtonPressed(_:)))
    let notificationButton   = UIBarButtonItem(image: notificationImage,  style: .plain, target: self, action: #selector(notificationViewButtonPressed(_:)))
    let profileButton = UIBarButtonItem(image: profileImage,  style: .plain, target: self, action: #selector(profileViewButtonPressed(_:)))
    let backButton   = UIBarButtonItem(image: backImage,  style: .plain, target: self, action: #selector(backButtonPressed(_:)))



    self.navigationItem.rightBarButtonItems = [profileButton,notificationButton,searchButton]
    self.navigationController?.navigationBar.tintColor = UIColor(hexString: "#373839")
    self.navigationItem.leftBarButtonItem = backButton

    self.setValues()
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(true)
    if #available(iOS 11.0, *) {
        self.navigationController?.navigationBar.prefersLargeTitles = false
        self.navigationController?.navigationItem.largeTitleDisplayMode = .never
        self.navigationController!.navigationBar.backgroundColor = UIColor.white
    } else {
        // Fallback on earlier versions
    }

    if (self.isBeingPresented || self.isMovingToParentViewController) {
        self.collectionView.animateViews(animations: animationsCanvas, reversed: false, initialAlpha: 0, finalAlpha: 1, delay: 0, duration: 0.07, animationInterval: 0.1, completion: nil)
    }
}

enter image description here

0 个答案:

没有答案