gpt4 book ai didi

ios - CollectionView 延迟选择

转载 作者:行者123 更新时间:2023-11-30 12:04:22 25 4
gpt4 key购买 nike

在选择我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com