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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

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

Reply
 
LinkBack Thread Tools Display Modes
Old 02-23-2010, 04:50 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 7
SDKTutor is on a distinguished road
Default UIImageView Subclassing? Help!?!?

I am making an app where I need to subclass an UIImageView because I will put code in there to control the sprites behavior. I have created two new files a Sprite.h and a Sprite.m. In the view controller of my app I am trying to add it by using the addSubview: method. I have the source code for you to look at and see if you can help me. Please help! Here's the source: TestApp.zip
SDKTutor is offline   Reply With Quote
Old 02-24-2010, 06:32 PM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

What is the problem? You didn't say if you're getting warnings, crashes, if it just fails to work, or what.

Edit: I took a look at your project. In your init method you were setting the center point, but not the width and height of the UIImageView. It doesn't change automatically when you change the image; the image gets squished instead. If you set the frame, your sprite appears OK:

Code:
@implementation Sprite
-(id) init {
	if ((self = [super init])) {
		self.image = [UIImage imageNamed:@"box.png"];		
		self.frame = CGRectMake(100, 100, 200, 200);
	}
	return self;
}
@end
You could also call [self initWithImage:] instead of [super init] and self.image = , if you want to use the dimensions of the image.

BTW it might be better to give you sprite class an instance variable to hold the UIImageView, instead of subclassing UIImageView. That way you won't get screwed if the definition of UIImageView changes, and you can better separate view-related stuff from model-related stuff later.
__________________

Free Games!

Last edited by smasher; 02-24-2010 at 06:46 PM.
smasher is offline   Reply With Quote
Reply

Bookmarks

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: 401
8 members and 393 guests
13dario13, iOS.Lover, JackReidy, jeroenkeij, Leslie80, Wikiboo, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

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