嘗試此功能。它爲我工作。
func showImagePickerWithAssetType
(
assetType: DKImagePickerControllerAssetType,
allowMultipleType: Bool,
sourceType: DKImagePickerControllerSourceType = [.Camera, .Photo],
allowsLandscape: Bool,
singleSelect: Bool) {
let pickerController = DKImagePickerController()
pickerController.assetType = assetType
pickerController.allowsLandscape = allowsLandscape
pickerController.allowMultipleTypes = allowMultipleType
pickerController.sourceType = sourceType
pickerController.singleSelect = singleSelect
// pickerController.showsCancelButton = true
// pickerController.showsEmptyAlbums = false
// pickerController.defaultAssetGroup = PHAssetCollectionSubtype.SmartAlbumFavorites
// Clear all the selected assets if you used the picker controller as a single instance.
// pickerController.defaultSelectedAssets = nil
pickerController.defaultSelectedAssets = self.assets
pickerController.didSelectAssets = { (assets: [DKAsset]) in
print("didSelectAssets")
self.assets = assets
if assets.count > 0 {
self.cameramoment.titleLabel?.textColor = UIColor.redColor()
//self.cameramoment.titleLabel?.alpha = 50
//self.cameramoment.titleLabel?.textColor = UIColor(red: 0.0, green: 184.0, blue: 214.0, alpha: 1.0)
}
else {
//self.cameramoment.setImage(UIImage (named: "grey_camera_32x32"), forState: .Normal)
self.cameramoment.titleLabel?.textColor = UIColor.lightGrayColor()
self.cameramoment.titleLabel?.alpha = 50
}
self.collectionview.reloadData()
}
if UI_USER_INTERFACE_IDIOM() == .Pad {
pickerController.modalPresentationStyle = .FormSheet;
}
self.presentViewController(pickerController, animated: true) {}
}
像這樣調用這個函數。
self.showImagePickerWithAssetType(DKImagePickerControllerAssetType.AllPhotos, allowMultipleType: true, allowsLandscape: true, singleSelect: false)
self.assets是定義爲,
var assets: [DKAsset] = []
要從DKAsset獲得圖像。嘗試這個。
for asset in assets {
asset.fetchImageWithSize(requiredImageSize, completeBlock: { image, info in
if let img = image {
let fixOrientationImage=img.fixOrientation()
cell.postmomentimage1.image = fixOrientationImage
}
})
}
你有什麼SOFAR做了什麼? –
你必須及時回覆。這樣你就可以得到你的答案。 –
張貼到目前爲止,我已經嘗試了很多使用Google搜索。共享一個鏈接,我也試圖遵循。 https://github.com/zhangao0086/DKImagePickerController/issues/122 –