简体   繁体   English

触摸图像,手指松开时消失吗?

[英]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.

相关问题 如何识别手指何时从屏幕上抬起? - How to recognise when a finger was lifted from the screen? 当手指在屏幕上抬起时,禁用捏识别器 - disable pinch recognizer when 1 finger is lifted on the screen 带有UIControlEventTouchDown的UIButton,直到手指抬起,图像才会变为选中状态 - UIButton with UIControlEventTouchDown, image won't change to selected until finger lifted 长按手势识别器仅在手指抬起时才会被触发 - Long Press Gesture Recognizer Only Fired When Finger is Lifted 在Ionic App中通过手指(触摸)裁剪图像 - Crop image via finger(touch) in Ionic App iOS:如何通过手指触摸将图像灰度转换为原始图像? - iOS : How to convert an image gray scale to original by finger touch? OpenGL iOS-无法在图像的手指触摸上应用模糊 - OpenGL iOS - apply blur on finger touch on image does not work 触摸并拖动UIButton,但在释放手指时不要触发它 - Touch and drag a UIButton around, but don't trigger it when releasing the finger 仅当触摸类型为手指时,如何将触摸事件传递给其他视图? - How to pass touch event to other views only when touchtype is finger? 用手指触摸移动时防止视图对象跳跃 - Prevent view object from jumping when moving with finger touch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM