Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-28-2009, 12:09 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Alexandria KY
Posts: 25
Default Display UIImage on UITextView?

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.

self.image=[UIImage imageNamed:@"Basketball_48.png"];
//startingPoint=[timePoints[0] getPoint];

startingPoint=CGPointMake(50.0,50.0);

[image drawAtPoint:startingPoint];

(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.

Thanks in advance for any help on this.
riderc1 is offline   Reply With Quote
Old 02-28-2009, 12:15 PM   #2 (permalink)
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,122
Default

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.
RickMaddy is offline   Reply With Quote
Old 03-02-2009, 09:59 AM   #3 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Alexandria KY
Posts: 25
Default

Quote:
Originally Posted by RickMaddy View Post
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?
riderc1 is offline   Reply With Quote
Old 03-02-2009, 04:12 PM   #4 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Alexandria KY
Posts: 25
Default

Quote:
Originally Posted by riderc1 View Post
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.
riderc1 is offline   Reply With Quote
Old 03-02-2009, 04:38 PM   #5 (permalink)
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,122
Default

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.
RickMaddy is offline   Reply With Quote
Old 03-03-2009, 08:05 AM   #6 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Alexandria KY
Posts: 25
Default

Quote:
Originally Posted by RickMaddy View Post
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]
riderc1 is offline   Reply With Quote
Old 03-03-2009, 12:46 PM   #7 (permalink)
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,122
Default

You missed the whole point of my suggestion. You never have more than one timer. Period. That makes it MUCH easier to keep track of.
RickMaddy is offline   Reply With Quote
Old 04-03-2009, 02:30 PM   #8 (permalink)
Registered Member
 
darbien's Avatar
 
Join Date: Apr 2009
Posts: 16
Default Need some advice?

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!
darbien is offline   Reply With Quote
Reply

Bookmarks

Tags
animation, uiimage, uitextview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 267
20 members and 247 guests
@sandris, AdamL, ADY, Dani77, diyora, FAED, F_Bryant, GHuebner, HDshot, headkaze, mer10, Oral B, prchn4christ, Rudy, smithdale87, Thompson22, timle8n1, Touchmint, twerner, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,749
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:57 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0