[英]Image on touch, disappears when finger lifted?
I have a question regarding touch or tap in xcode. 我有一个关于在xcode中触摸或点击的问题。
I was wondering if anyone could help me figure out how to make an image appear when the user taps the screen, and disappear when they lift their finger. 我想知道是否有人可以帮助我弄清楚如何使图像在用户点击屏幕时出现,而在用户抬起手指时消失。 For example when they're holding down their finger, a smiley face might show underneath it, and when they lift, it disappears. 例如,当他们按住手指时,笑脸可能会出现在手指下面,而抬起手指时,笑脸就会消失。
I appreciate the help, thank you. 感谢您的帮助,谢谢。
Give a look at UIPanGestureRecognizer
. 看看UIPanGestureRecognizer
。 You can associate it to a UIImageView
and define its handler method so that then it is in the begin phase, the image is shown; 您可以将其关联到UIImageView
并定义其处理程序方法,以便随后在开始阶段中显示图像。 in the end
phase, the image is hidden. 在end
阶段,图像被隐藏。
I hope this gives you a clue as to one way to go. 我希望这可以为您提供一条线索。
Add some of your code if you need more help, please. 如果需要更多帮助,请添加一些代码。
The easiest way to do this would be to create an invisible button. 最简单的方法是创建一个不可见的按钮。
Set it's type to "Custom" and the size to the size of your image. 将其类型设置为“自定义”,并将大小设置为图像的大小。
Select "Default" under "State config" in the attributes selector and make sure there's no image selected. 在属性选择器的“状态配置”下选择“默认”,并确保未选择任何图像。 Then select the state config "Highlighted" and select your image. 然后选择状态配置“突出显示”并选择您的图像。 When I did this the button size jumped back to the default for some reason, and I had to set it back to my desired size. 当我这样做时,由于某种原因,按钮的大小跳回到了默认值,并且我不得不将其设置回我想要的大小。
Once you've done this the buttons switches to it's highlighted state when you touch it, and your image appears. 完成此操作后,触摸按钮时按钮将切换到突出显示状态,并显示图像。
You can attach an IBAction to the button or not, as desired. 您可以根据需要将IBAction附加至按钮或不附加至按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.