Create an image folder that can be selected multiple times in collectionView.
The screen movement is as follows
Select one image (s)
2 Press the enter button
3Selected image is displayed on another screen
I think you can edit images in the default image folder of iphone.
If i edit the image and select the edited image, the image before editing will be displayed in 3.
How can I select the edited image?
The screen display at one point shows the edited image,
Since it is the pre-edit image at the 3 time point, isn't the storage method of the value stored at the time of cell selection good? I think.
In addition, since the display of 3 does not output the retained image as it is, it is displayed from the URL of the image, so I think that the URL is not accurate.
The source when selecting a cell is as follows
// Manage images in cache
var fetchResult: PHFetchResult<PHAsset>!
override func collectionView (_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// Get the ASSET for the cell
let asset = fetchResult.object (at: indexPath.item)
guard let cell: GridViewCell = collectionView.cellForItem (at: indexPath) as? GridViewCell else {return}
// If the selected image is a panoramic image
if asset.mediaSubtypes == PHAssetMediaSubtype.photoPanorama {
let title = "Select image"
let message = "Panorama cannot be selected"
let okText = "OK"
let alert = UIAlertController (title: title, message: message, preferredStyle: UIAlertController.Style.alert)
let okeyButton = UIAlertAction (title: okText, style: UIAlertAction.Style.default, handler: {(action) in
// cell release
collectionView.deselectItem (at: indexPath, animated: true)
})
alert.addAction (okeyButton)
self.present (alert, animated: true, completion: nil)
} else {
// Store URL
asset.getURL (completionHandler: {(action) in
self.imagePathList.append (action!)
})
// Store local identifier
selectedAssetLocalIdentifiers.append (cell.representedAssetIdentifier)
// Image storage
imageList.append (cell.imageView.image!)
// reload cell
reloadSelectedCells ()
disableUserInteractionIfNeed (collectionView)
}
}
extension PHAsset {
func getURL (completionHandler: @escaping ((_ responseURL: URL?)->Void)) {
if self.mediaType == .image {
let options: PHContentEditingInputRequestOptions = PHContentEditingInputRequestOptions ()
options.canHandleAdjustmentData = {(adjustmeta: PHAdjustmentData)->Bool in
return true
}
self.requestContentEditingInput (with: options, completionHandler: {(contentEditingInput: PHContentEditingInput ?, info: [AnyHashable: Any])->Void in
completionHandler (contentEditingInput! .fullSizeImageURL as URL?)
})
} else if self.mediaType == .video {
let options: PHVideoRequestOptions = PHVideoRequestOptions ()
options.version = .original
PHImageManager.default (). RequestAVAsset (forVideo: self, options: options, resultHandler: ((asset: AVAsset ?, audioMix: AVAudioMix ?, info: [AnyHashable: Any]?)->Void in
if let urlAsset = asset as? AVURLAsset {
let localVideoUrl: URL = urlAsset.url as URL
completionHandler (localVideoUrl)
} else {
completionHandler (nil)
}
})
}
}
}
-
Answer # 1
Related articles
- ios - does not change when uibutton is selected
- ios - how to use swiftpm with multiple projects in workspace
- i want to read multiple excel files in a folder with python and output them as txt
- c # - display multiple selected items with check boxes of xanarinandroid with displayalert
- python (tkinter): i don't want to allow multiple rows to be selected in treeview's select mode, but i want to keep the function
- python - how to comment out multiple lines selected in editor with one touch?
- vba - i created a macro that creates multiple emails at once, but when i changed the path acquisition, the loop stopped
- ios - i want to display the image selected in the album (camera roll) on the uiimageview installed in the customcell (using xib
- ios - [swift] when acquiring multiple images of dkimagepickercontroller, they cannot be acquired in order
- ios - i want to correctly save multiple text data in sqlite
- ios - the action sheet created in swift is not displayed, and the items in the action sheet open without permission
- the certificate created in monaca's ios build settings becomes an invalid certificate in the apple developer program
- ios - i want to generate multiple custom views in uistackview
- ios - i can't press a button created with a custom cell
- xcode - i don't know how to delete multiple nodes created with a for statement
- ios - swiftui/i want to change the colors of multiple objects at once
- ios - i want to get the index number of the selected pin in the mkpointannotation array
- ruby - batch action for multiple selected data [rails]
- i want to monitor a folder with python and read the file when a new file is created in that folder
- ios - i want to limit the number of characters for multiple uitextviews
- swift : I want to upload /download photos taken with an app to iCloud
- ios - the layout of collectionview doesn't work as expected
- ios - i want to change the color of the custom cell from the [swift] setting screen
- ios - [in app store connect] i want to submit the app to the app store for review, but an error occurs
- ios - [swift] i want to register user name at the same time as signing up with firebaseauth
- ios - navigationitem does not work [left, right]
- ios app development question about the notation of the function executed when an item is selected in the alert display
- ios - difference between ":" and "=" when declaring variables and constants
- ios - navigationitem uisearchbar does not work well
- ios - i want to reload the tableview of another view controller when i tap the button
Self-solved.
It was possible to cope by setting the return of getURL to false.