简体   繁体   English

图像视图点击手势

[英]Image View Tap Gesture

I am new to swift, so I make exercises through apple developer center, I coded with the project named Food Tracker. 我是新手,所以我通过Apple开发人员中心进行了练习,并使用名为Food Tracker的项目进行了编码。 My codes is totally the same with the site samples, but when I click the image there is nothing to see. 我的代码与站点样本完全相同,但是当我单击图像时,看不到任何内容。 So it doesn't work. 因此它不起作用。 and there is no error. 而且没有错误。

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    //This info dictionary contains multiple representations of the images, and this uses the original. 
    let selectedImage=info[UIImagePickerControllerOriginalImage]as! UIImage

    //set photoImageView to display the selected image 
    photoImageView.image=selectedImage

    dismissViewControllerAnimated(true, completion: nil )
    print("picker image")
}

When i click the image image picker doesn't work. 当我单击图像时,图像选择器不起作用。 And "picker image" is not showed. 并且不显示“选择图像”。

screenshot: 屏幕截图: 在此处输入图片说明

The error is because of the image view interaction=NO, so choose the image view and see the attributes inspector, then you will find "interaction" label, if checkbox "user interaction enabled" is not checked, you will get the error, so check the user interaction enabled, then you will get the right answer. 该错误是由于图像视图的interaction = NO,所以选择图像视图并查看属性检查器,然后您将找到“交互”标签,如果未选中“启用用户交互”复选框,则会出现此错误,因此检查已启用的用户交互,则您将获得正确的答案。 The important thing is just the attribute called "user interaction enabled" of image view. 重要的只是图像视图中称为“已启用用户交互”的属性。

enter image description here 在此处输入图片说明

The UIImageView 's userInteractionEnabled is NO by default. UIImageViewuserInteractionEnabled默认为NO It needs to set YES for receiving touch events. 它需要设置为YES以接收触摸事件。

When I code like this , i also have another error which is something like the following."there is more than one view". 当我这样编写代码时,我还会遇到另一个错误,如下所示:“有多个视图”。 So when i click the tap gesture, i find there is not only one "Photo Image View" below the "gestureRecognizers", so i delete the image view and make there only one image view below the gesture "gestureRecognizers", then i don't have the error.. 因此,当我单击轻击手势时,我发现在“ gestureRecognizers”下不仅只有一个“照片图像视图”,因此我删除了该图像视图,并在“ gestureRecognizers”手势下仅使一个图像视图成为一体,然后我没有没有错误..

So at last you should get this like the picture. 所以最后您应该像图片一样得到它。 enter image description here 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM