gpt4 book ai didi

photo - MWPhotoBrowser - 如何实现删除照片功能?

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

我正在使用 MWPhotoBrowser对于我的应用程序。我需要为我的用户提供删除功能。有什么方法可以实现删除特定照片或多张照片的功能?

需要快速帮助。

最佳答案

enter image description here

我通过从库外部添加这个扩展来迅速做到这一点:

extension MWPhotoBrowser {

public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()

if let _ = valueForKey("_gridController") as? MWGridViewController {
let leftButtonItem = editButtonItem()
//leftButtonItem.tintColor = QorumColors.ThemeWhite
navigationItem.leftBarButtonItem = leftButtonItem
} else {
navigationItem.leftBarButtonItem = nil
}
}

public override func setEditing(editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)

if editing {
navigationItem.leftBarButtonItem?.title = "Delete"
//navigationItem.leftBarButtonItem?.tintColor = QorumColors.Nickname

displaySelectionButtons = true
title = "Delete Photos"

let gridController = valueForKey("_gridController") as! MWGridViewController
gridController.selectionMode = displaySelectionButtons
gridController.collectionView!.reloadData()
} else {
let nav = self.navigationController as! TempPresentVC
let photosToDelete = nav.selectedPhotos

let afterButtonPress = {
//self.navigationItem.leftBarButtonItem?.tintColor = QorumColors.ThemeWhite

self.displaySelectionButtons = false
self.updateNavigation()

let gridController = self.valueForKey("_gridController") as! MWGridViewController
gridController.selectionMode = self.displaySelectionButtons
gridController.collectionView!.reloadData()
}

guard photosToDelete.count > 0 else {
afterButtonPress()
return
}

let title = "Delete Photo"
let message = "Are you sure you want to delete these photos?"
let action = "Delete"
let cancelAction = "Cancel"

let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
let declineButton = UIAlertAction(title: cancelAction, style: .Default, handler: { (action: UIAlertAction) in
afterButtonPress()
})
let acceptButton = UIAlertAction(title: action, style: .Default, handler: { (action: UIAlertAction) in
afterButtonPress()
})
alert.addAction(declineButton)
alert.addAction(acceptButton)
UIApplication.topMostController().presentVC(alert) //private lib
}
}
}



class TempPresentVC: UINavigationController, MWPhotoBrowserDelegate {
var selectedPhotos = [Int]()

func photoBrowser(photoBrowser: MWPhotoBrowser!, photoAtIndex index: UInt, selectedChanged selected: Bool) {
if selected {
selectedPhotos.append(index.toInt)
} else {
selectedPhotos.removeObject(index.toInt)
}
}
}

这不允许您在单个照片查看模式下删除照片,但从这个代码库开始,该部分将很容易实现。

请注意,我在里面使用的一些东西是我在其他类中编写的私有(private)函数,但它们的作用应该很清楚。

关于photo - MWPhotoBrowser - 如何实现删除照片功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21267815/

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