gpt4 book ai didi

ios - 我如何确定 UIImagePickerView 的呈现位置?

转载 作者:行者123 更新时间:2023-11-28 11:58:38 25 4
gpt4 key购买 nike

我有两个按钮,button1button2。点击这些按钮将显示 UIImagePickerViewController。在委托(delegate)方法 didFinishPickingMediaWithInfo 中,我如何确定 UIImagePickerViewController 是从哪个按钮的操作中呈现的?

最佳答案

您可以使用 Tag 属性来识别您的对象,最初为您的每个 UIButton 分配标签,然后在 UIImagePickerController 出现时分配按钮标记为 UIImagePickerController.view.tag,例如

例如

 @IBAction func buttonOneClick(_ sender:UIButton) {
//... code for present the UIImagePickerController
yourimagePicker.view.tag = sender.tag
}
@IBAction func buttonTwoClick(_ sender:UIButton) {
//... code for present the UIImagePickerController
yourimagePicker.view.tag = sender.tag
}

或者为您的 UIButton 创建通用方法

 @IBAction func buttonPresentImage(_ sender:UIButton) {
//... code for present the UIImagePickerController
yourimagePicker.view.tag = sender.tag
}

最后你可以识别 UIImagePickerController 委托(delegate)方法

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if picker.view.tag == button1.tag {
// its button1
} else {
// its button2
}
}

关于ios - 我如何确定 UIImagePickerView 的呈现位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50443304/

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