gpt4 book ai didi

ios - 从 UIImagePicker 设置多个按钮图像

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

在我看来,我有三个 4 按钮。当您单击一个按钮时,它会弹出 UIPickerView,因此您可以从库中选择一个图像用作个人资料图像。但是,当调用 didFinishPickingMediaWithInfo 时,它会为同一个按钮存储不同的照片。单击按钮 1,选择图像,从按钮 1 设置图像单击按钮 2,选择图像,再次为按钮 1 设置图像,而不是按钮 2。所有 4 个按钮都一样。继续为第一个按钮设置图像。

func promptForCamera() {

let controller = UIImagePickerController()
controller.sourceType = UIImagePickerControllerSourceType.Camera
controller.delegate = self
self.presentViewController(controller, animated: true, completion: nil)
}

func promptForPhotoRoll() {

let controller = UIImagePickerController()

controller.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
controller.delegate = self
self.presentViewController(controller, animated: true, completion: nil)
}

func promptForSource() {
let actionSheet = UIActionSheet(title: "Image Source", delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: nil, otherButtonTitles: "Camera", "Photo Roll")
actionSheet.showInView(view)

}

func actionSheet(actionSheet: UIActionSheet!, clickedButtonAtIndex buttonIndex: Int) {
if buttonIndex != actionSheet.firstOtherButtonIndex{
if buttonIndex != actionSheet.firstOtherButtonIndex{
promptForCamera()
}
else{
promptForPhotoRoll()
}
}
}

func imagePickerControllerDidCancel(picker: UIImagePickerController!) {
dismissViewControllerAnimated(true, completion: nil)
}

func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]!) {
let image = info[UIImagePickerControllerOriginalImage] as UIImage

self.p1Image = image


self.dismissViewControllerAnimated(true , completion: nil)

p1ImageButton.setImage(self.p1Image, forState: UIControlState.Normal)


}



@IBAction func p1PhotoTapped(sender: AnyObject) {


if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera){

promptForSource()


}
else{

promptForPhotoRoll()


}

}

显然,我知道在这个 didFinishPickingMedia 函数中,我正在为 p1ImageButton 设置图像。但是我如何更改此功能以便它为所选的相关按钮设置图像?我是否需要 4 个不同的 didFinishPickingWithMedia 函数(甚至可能)?每次选择按钮时,它都会调用 didFinish 方法。我需要传递某种参数吗?希望这一切都有意义。

最佳答案

将您的 4 个 ImagePickerController 保存在变量中,并在您的 imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]!) 方法中做出决定。

if (picker == pickerBla)
{

}
else if (picker == ...)
{

}

关于ios - 从 UIImagePicker 设置多个按钮图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25695002/

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