gpt4 book ai didi

ios - 屏幕突然变白

转载 作者:行者123 更新时间:2023-11-30 14:02:39 25 4
gpt4 key购买 nike

我正在开发一个项目,我想在图像中添加引号。我设置了我的 Storyboard,效果很好。

现在我添加了向 UICollectionView 添加图像的功能。这也很完美,但由于某种原因,在我启动应用程序时进行一些更改后,仅出现白色屏幕。

你可以看到我的project here on GitHub

如果您不想下载该应用程序,这是我的 NewImagesCollectionViewController 代码:

import UIKit

private let reuseIdentifier = "newImageCell"

class NewImagesCollectionViewController: UICollectionViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {

let imagePicker = UIImagePickerController()

var newImageCollection:[UIImage] = []

override func viewWillAppear(animated: Bool) {
collectionView?.reloadData()
print(newImageCollection)
}

override func viewDidLoad() {
super.viewDidLoad()

imagePicker.delegate = self
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

override func viewWillLayoutSubviews() {
collectionView?.collectionViewLayout.invalidateLayout()
}

override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}


override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if newImageCollection.count > 0 {
return newImageCollection.count
} else {
return 0
}
}

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! NewImagesCollectionViewCell
cell.newImageView.image = newImageCollection[indexPath.row]
return cell
}

//MARK: Adding Images
@IBAction func addPicturesPressed(sender: UIBarButtonItem) {
imagePicker.allowsEditing = false
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
presentViewController(imagePicker, animated: true, completion: nil)
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
print("didfinishpicking")
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
print("ADD pickedImage!")
newImageCollection.append(pickedImage)
}
dismissViewControllerAnimated(true, completion: nil)
}
}

最佳答案

您在使用此行时遇到问题:

collectionView?.collectionViewLayout.invalidateLayout()

在您的 viewWillLayoutSubviews 方法中。

只需评论并检查即可。

关于ios - 屏幕突然变白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32796776/

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