I'm struggling getting this to work. I have a UITextView that displays lyrics to a song. I am trying to add a "ball" that bounces to each word in time with the music. (You've seen these before - sing-alongs?).
However, I'm not seeing my image display. Here is a quick explanation of what I currently have in my app:
A view controller draws a Navigation bar at the top of the screen with a Done button (to flip back to the previous screen). Below the navigation bar, I have:
Lyrics *textView=[[Lyrics alloc] initWithFrame:CGRectMake(0.0,45.0,320.0,430.0)];
[textView setEditable:NO];
Class Lyrics extends UITextView. I wanted to disable user typing, but still accept touch events. Class Lyrics contains that code. Lyrics reads in a data file to display the words to the song. No problems displaying the text.
Next, I'm trying to add the ball. I thought I might get away with using a UIImage and telling it a CGPoint to display. My code compiles, no warnings. When I run it, I don't see the graphics.
(timePoints, commented out, is an data array containing CGPoints and time data to eventually be used to bounce the ball.)
Any ideas? I commented out my UITextView, thinking that perhaps the UIImage was hiding below it. No dice. I also experimented with overlaying a UIImageView and trying to fit my UIImage into it - no luck.
The UIImage will be moving around the screen. It will basically "bounce" from word to word.
The 'drawAtPoint method can only be used with a graphics context typically obtained from a view's drawRect method.
For what you want to do the easiest approach would be to put the UIImage in a UIImageView and set the image view's frame to match the location it should be displayed.
I would add the image view as a subview of the same view you added the text view. That way the "ball" can easily appear outside or on the edge of the text view in addition to inside the text view.
The 'drawAtPoint method can only be used with a graphics context typically obtained from a view's drawRect method.
For what you want to do the easiest approach would be to put the UIImage in a UIImageView and set the image view's frame to match the location it should be displayed.
I would add the image view as a subview of the same view you added the text view. That way the "ball" can easily appear outside or on the edge of the text view in addition to inside the text view.
Thanks - I don't know why I didn't see that solution. I had a small issue with "stacking" my views - I thought it would have been the first view declared is on the bottom, and subsequent views got stacked on top. I'll take a look later and will likely see the light.
I'm trying to decide how to implement the animation next. I need it to start up when the view is "flipped" into view. Is there a way to add threads or would something like an IBAction handle this?
Thanks - I don't know why I didn't see that solution. I had a small issue with "stacking" my views - I thought it would have been the first view declared is on the bottom, and subsequent views got stacked on top. I'll take a look later and will likely see the light.
I'm trying to decide how to implement the animation next. I need it to start up when the view is "flipped" into view. Is there a way to add threads or would something like an IBAction handle this?
I had problems implementing a thread for this. It seems whenever I tried to use NSSleep, sleep, etc - my entire program would pause. In other languages I'm familiar with, this is not the expected behavior.
I am currently using an array of NSTimer's to handle my animation. It seems kind of ugly to me - but it works. The song I'm using has 80 words. I end up creating 80 timers (staggered by the amount of time I generated with touchEvents).
The animation currently just consists of: UIImageView.center=new X,Y values.
Why would you create an array of timers? Just have an array of delay values. Create a timer with the first delay. When it goes off create a new timer with the next delay, etc.
Why would you create an array of timers? Just have an array of delay values. Create a timer with the first delay. When it goes off create a new timer with the next delay, etc.
I think I need an array so I can keep a reference to individual timers. In my app, the user might tap a button to end the current screen and flip back to the main screen. In that event, I need to stop the timers that haven't fired yet.
I'm currently researching how to do the following in my code:
1. Detect if a timer still exists. Since I have this in an array, I should be able to check for null? Ex. if(timers[i]==NULL)
2. If a timer has not fired and the user wants to go back to the previous screen, get rid of the timer. [timers[i] invalidate]
I'm actually planning to develop a text reading game for children that will be using some animation inside the UITextview as well. The animation will be quite involved, as there may be many sprite active at one once (10-20+). The text will be non-editable and unicode support is needed (Japanese, Chinese)
However, I'm having a hard time deciding if I should use the suggested method of using UITextview and put UIImageview as subview for the animated sprites, or actually redo the whole functionality of UITextview using OpenGL ES based text rendering so it can work better with the animated sprites.
I'm basically not sure if I just use UITextview and UIImageview the frame rate will be able to support all the animation activities. Do you guys have any suggestions? Any advice will be greatly appreciated!