0
選擇我的collectionview單元格時,我收到第二長延遲。這裏是我目前的代碼收集視圖確實選擇:使用CollectionView進行延遲選擇
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!
}
我正在使用UIViewControllerAnimatedTransitioning。我相信我的UIViewControllerAnimatedTransitioning沒有延遲。我的CollectionView選擇功能似乎有問題。如果在打印語句的didSelect函數中切換我的代碼,則不存在延時。
您是否在下一個VC中使用了一些IBInspectable,或者在下一個VC的ViewDidLoad中加載了一些笨重的數據。如果您提供的IBInspecatble的UIView的一些其他元素比視圖將加載抱怨不可滿足的限制。而選擇適當的一個將需要幾秒鐘的時間。 – Amit
將此行'self.navigationController?.pushViewController(vc,animated:true)'移動到方法'didSelectItemAt'的末尾。在推送之前,您應該設置目標對象的所有成員 – Lamar