gpt4 book ai didi

swift - UITapGestureRecognizer 不起作用

转载 作者:行者123 更新时间:2023-11-30 14:08:03 29 4
gpt4 key购买 nike

我想设置一个 UITapGestureRecognizer 以允许用户添加图像作为配置文件。我设置了代码,但是当我触摸图像时,什么也没有发生。代码如下:

@IBAction func selezionaFoto(sender: UITapGestureRecognizer) {

fieldNome.resignFirstResponder()

func selezionaLibreria(action : UIAlertAction!) {
UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.Default, animated: true)
CameraManager.sharedInstance.newImageFromLibraryForController(self, editing: false)
}

func scattaFoto(action : UIAlertAction!) {
UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.Default, animated: true)
var circle = UIImageView(frame: UIScreen.mainScreen().bounds)
circle.image = UIImage(named: "overlay")
CameraManager.sharedInstance.newImageShootForController(self, editing: false, overlay:circle)
}

var myActionSheet = UIAlertController(title: NSLocalizedString("ACTION_IMAGE_TITLE", comment: ""),
message: NSLocalizedString("ACTION_IMAGE_TEXT", comment: ""),
preferredStyle: UIAlertControllerStyle.ActionSheet)

myActionSheet.addAction(UIAlertAction(title: NSLocalizedString("BUTTON_LIBRARY", comment: ""),
style: UIAlertActionStyle.Default,
handler: selezionaLibreria))

myActionSheet.addAction(UIAlertAction(title: NSLocalizedString("BUTTON_SHOOT", comment: ""),
style: UIAlertActionStyle.Default,
handler: scattaFoto))

myActionSheet.addAction(UIAlertAction(title: NSLocalizedString("BUTTON_CANCEL", comment: ""),
style: UIAlertActionStyle.Cancel,
handler: nil))

self.presentViewController(myActionSheet, animated: true, completion: nil)

}


func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}

func incomingImage(image: UIImage) {
UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)
immagine.image = image
immagineSelezionata = image
}

func cancelImageSelection() {
UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)
}

Storyboard中的第一个元素是图像,然后是文本字段。

最佳答案

我最近遇到了同样的问题,我有复杂的 View 层次结构,并且手势没有响应操作的原因是一个 superView 设置为 isUserInteractionEnabled 为 false,正如您可能知道的,应用程序如何接收手势以及转到链中的响应者,就是这条链中的所有UIResponders都应该isUserInteractionEnabled = true,才能传递到最顶层的 View 。我假设您遇到了同样的情况,因此只需检查层次结构中的所有 View 即可。

关于swift - UITapGestureRecognizer 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32101637/

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