在选择我的 CollectionView 单元格时,我遇到了第二次长时间延迟。这是我当前选择的 Collection View 代码:
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 Did 选择功能似乎有问题。如果将我的 didSelect 函数中的代码切换为打印语句,则不再有延迟。
最佳答案
我有两个解决方案:
1:可能不是:我猜测它会产生令人讨厌的延迟,因为您的应用程序需要一段时间才能运行代码来获取 nib 文件,并在执行过程中更改所有这些内容不应该。
2:可能:也许在真实设备上运行它会有所帮助。 Xcode 总是有错误,所以不用担心。 :)
关于ios - CollectionView 延迟选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46841350/