Je reçois un second long délai lors de la sélection de ma cellule de vue de collection. Voici mon code actuel pour une vue de collection a sélectionner:Délai avec CollectionView Sélection
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let vc = PopUpCellViewController(nibName: "PopUpCellViewController", bundle: nil)
self.navigationController?.pushViewController(vc, animated: true)
print("called")
let cell = collectionView.cellForItem(at: indexPath) as! AnnotatedPhotoCell
sourceCell = cell
vc.picture = resizeImage(image: cell.imageView.image!, targetSize: CGSize(width: (view.bounds.width - 45),height: 0))
vc.comment = cell.commentLabel
var image = UIImage(named: "back_button_thick")
image = image?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
self.navigationController?.navigationBar.backIndicatorImage = image
self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = image
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: " ", style: UIBarButtonItemStyle.plain, target: nil, action: nil)
}
func resizeImage(image: UIImage, targetSize: CGSize) -> UIImage {
let size = image.size
let widthRatio = targetSize.width/image.size.width
// Figure out what our orientation is, and use that to form the rectangle
var newSize: CGSize
newSize = CGSize(width: size.width * widthRatio, height: size.height * widthRatio)
// This is the rect that we've calculated out and this is what is actually used below
let rect = CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height)
// Actually do the resizing to the rect using the ImageContext stuff
UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0)
image.draw(in: rect)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage!
}
J'utilise un UIViewControllerAnimatedTransitioning. Je suis confiant qu'il n'y a pas de retard avec mon UIViewControllerAnimatedTransitioning. Il semble y avoir un problème avec ma fonction CollectionView Did select. Si passer mon code dans ma fonction didSelect pour une instruction d'impression, il n'y a pas de délai longera.
Utilisez-vous du IBInspectable dans le prochain circuit virtuel ou chargez-vous des données encombrantes dans ViewDidLoad du prochain circuit virtuel? Si vous fournissez IBInspecatble de UIView à un autre élément que la vue chargera avec des contraintes insatisfiables. Et pour choisir celui qui convient, cela prendra quelques secondes. – Amit
déplacez cette ligne 'self.navigationController? .pushViewController (vc, animé: true)' à la fin de votre méthode 'didSelectItemAt'. Vous devez définir tous les membres de l'objet de destination avant de le pousser – Lamar