简体   繁体   English

UIButton自定义突出显示

[英]UIButton Custom Highlight

The app I am currently developing uses draggable UIButtons created programmatically. 我当前正在开发的应用程序使用以编程UIButtons创建的可拖动UIButtons They work very well: after creating them, I add a UIPanGestureRecognizer which enables me to track their position as they are dragged. 它们工作得很好:创建它们之后,我添加了一个UIPanGestureRecognizer ,使我能够在拖动它们时跟踪它们的位置。

I also have added a different background for their UIControlStateHighlighted . 我还为其UIControlStateHighlighted添加了不同的背景。 However, I would like more than just a different background image: I would like the button to grow to a larger size when it is first touched. 但是,我不仅希望获得不同的背景图像:我希望在首次触摸按钮时将其增大到更大的尺寸。 This behavior should look a little like what happens when one presses a letter on the keyboard. 这种行为看起来应该有点像在键盘上按一个字母时发生的情况。

I have tried to change its size in the touchesBegan of the UIPanGestureRecognizer object, but it does not respond when first touched: only when the user starts dragging. 我试图在UIPanGestureRecognizer对象的touchesBegan中更改其大小,但第一次触摸时它没有响应:仅当用户开始拖动时。

Thank you in advance for your help 预先感谢您的帮助

Move Me is a sample project provided by Apple which demonstrates how to track an object with gestures and touches, and also has code which changes the size of the object. “移动我”是Apple提供的一个示例项目,演示了如何使用手势和触摸来跟踪对象,并且还具有更改对象大小的代码。 It is done with a UIView, but the code should be easily portable to a UIButton. 它是通过UIView完成的,但是代码应易于移植到UIButton中。 Hope that helps! 希望有帮助!

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

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