在didSelectItemAt Swift上调整视图高度

时间:2018-01-29 14:21:34

标签: swift layout keyboard sfsafariviewcontroller

我有一个iOS自定义键盘,当选择了集合视图中的项目时,该键盘包含SFSafariViewController。自定义键盘与普通键盘的高度相同,但我想在使用时弹出webview。我正在尝试根据需要进行布局,但没有任何运气。我错过了什么? 这是功能 - 可以发布更多

func collectionView(_ collectionView:UICollectionView,didSelectItemAt indexPath:IndexPath){

    if(collectionView == self.key.colImages)
    {
        if (self.articles[indexPath.item].url) != nil{
            let sfViewController = SFSafariViewController(url: URL(string: (self.articles[indexPath.item].url!))!, entersReaderIfAvailable: true)

            //MARK: - sets background and text color for Safari

            if #available(iOS 10.0, *) {
                sfViewController.preferredBarTintColor = .white
                sfViewController.preferredControlTintColor = UIColor(red:0.19, green:0.58, blue:0.91, alpha:1.0)
            } else {
                sfViewController.view.tintColor = .white
            }
            self.present(sfViewController, animated: true, completion: nil)
            sfViewController.delegate = self

            //MARK: - Copies url
            UIPasteboard.general.string = ((self.articles[indexPath.item].url!))

            //Trying to resize browser window
            self.heightConstraint.constant = 500.0
            self.view.layoutIfNeeded()

            UIView.animate(withDuration: Double(0.5), animations: {
                self.heightConstraint.constant = 0
                self.view.layoutIfNeeded()
            })

        }

         }
    else
    {

        self.fetchArticles(fromSource: "\(categoriesArray[indexPath.row])")
        //URLCache.shared.removeAllCachedResponses()

                }

}

0 个答案:

没有答案
相关问题