views:

1053

answers:

2

I'm developing Piano App for iPhone. I'd like to develop smooth-scrollable keyboard (like Music Sampler).

I put a custom view(1440px x 120px) in UIScrollView. I wanted to use OpenGL because Quartz is too slow. But I couldn't make OpenGL view in 1440px.

Any idea to make a faster & large-sized custom view?

Thank you.

A: 

Using OpenGL for this would be overkill and a bad idea. You'll waste a lot of time setting up things that are already provided for you in UIViews, such as touch handling.

There are two ways for laying out nonstandard keyboards on the iPhone that I've seen. The first is to create a static UIImageView that contains a representation of your entire keyboard, capture touch events within this view, and match the location of those touch events to where your prerendered keys are on the keyboard. If the user hit one of your virtual keys, you overlay some sort of image that shows the key popping out at you and you process the keypress. I believe this is the approach that many of the calculator applications take.

An alternative way is to set up each of your keys as separate UIViews, lay them out within a larger superview, and have each do processing of their touch events. This is what I do in the interface shown here. The lower menu consists of two submenus, and within the submenus each of the menu buttons are separate UIViews. Their content (the border, gloss, and text) is rendered via Quartz, but that rendering only happens once. Because these views are layer-backed, they cache their drawn content and animate and scroll very smoothly. Touch events trigger each menu item's action. Note that the top half of the menu is contained within a UIScrollView so that you can scroll for more options.

My personal recommendation is to use the latter approach, because dynamically drawing your piano keys at startup lets you experiment with different key sizes and shapes without having to redo your art every time.

Brad Larson
Fantastic idea!I'll try latter one.Thank you!
fish potato
A: 

Any instance of UIView has a maximum size of 1024x1024. Doesn't matter if it is OpenGL or not. You can have a scrollable area larger than that, but you will have to build it from multiple tiled views.

benzado