开发者

Ios UIButton subclassing with OpenGL

开发者 https://www.devze.com 2023-04-12 05:40 出处:网络
Is it possible to create subclasses of UIButt开发者_如何学Goon which do the button drawing in OpenGL ES? I have a game app that uses only OpenGL ES so far and I do not want to add composited UIkit ele

Is it possible to create subclasses of UIButt开发者_如何学Goon which do the button drawing in OpenGL ES? I have a game app that uses only OpenGL ES so far and I do not want to add composited UIkit elements on top of this both for performance and aesthetic reasons. Then again I do not really want to implement hit testing of touches against rects because to do it correctly as apple does with inner and outer rects and various state transitions is quite a lot of code. What I really want is to have the UIButton do all the touch state changes but have it do no drawing, while allowing me to draw the buttons myself in various states using OpenGL along with all the rest of my drawing code. Any suggestions or code examples of how to proceed?


I found that one answer to this question would be to make use of UIButton but use Custom style. Then if you do not set the actual images for the button states it does not draw anything at all, but still functions as a button by calling you back when the desired action is detected in the rectangle that you supply. This way you can make regions of an GLES texture active as buttons. You can get callbacks when the button is touched or released with or without action and you can update your texture yourself in response to these if desired. However in the end I did not do this, but just used the Custom buttons with images as per normal UIKit use. I did not find any excess slow down of my app using UIKit on top of OpenGL ES.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号