2010-06-01 2 views
0

Название этого вопроса должно быть довольно понятным. Я делаю приложение, которое включает в себя несколько UIImageView, которые служат той же цели. Это просто разные размеры. Во всяком случае, я решил, что лучшим решением было сделать подклассы UIImageView, связать субкассы в IB и работать оттуда. Мой код должен объяснить это лучше -Подкласс UIImageView с CGRectIntersectsRect - помощь!



#define kPausedStatePaused 1 
#define kPausedStatePlay 2 

#import "Game.h" 
#import "ScoreSystem.h" 

@interface Doctor : UIImageView 
{ 
} 
@end 

@interface Ground : UIImageView 
{ 
} 
@end 

@interface Wall : UIImageView 
{ 
} 
@end 

@interface Electric_Wire : UIImageView 
{ 
} 
@end 


@implementation Game 

/* 
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { 
     // Custom initialization 
    } 
    return self; 
} 
*/ 

/* 
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
    [super viewDidLoad]; 
} 
*/ 

- (IBAction)pause { 
UIAlertView *pause = [[UIAlertView alloc] initWithTitle:@"Pause" message:nil delegate:self cancelButtonTitle:@"Quit" otherButtonTitles:@"Play", nil]; 
[pause show]; 
[pause release]; 
pauseint = kPausedStatePaused; 
} 

- (void)viewDidAppear { 
pauseint = kPausedStatePlay; 
} 

- (void)loop { 
Doctor *doctorview; 
Ground *groundview; 
if (CGRectIntersectsRect(doctorview, groundview)) { 

} 
} 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
if ([alertView.title isEqual:@"Pause"]) { 
    if(buttonIndex == 0) 
    [self dismissModalViewControllerAnimated:YES]; 
    pauseint = kPausedStatePlay; 
} 
} 

// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

- (void)didReceiveMemoryWarning { 
// Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

// Release any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
    [super dealloc]; 
} 


@end 

Unsurprisingly, Xcode дал мне «несовместимый тип для CGRectIntersectsRect» ошибки.

ответ

1

Вы должны пройти каркас Вид, а не вид и сами к этой функции:

CGRectIntersectsRect(doctorview.frame, groundview.frame) 
+0

ой, дух. Это был один из моих моментов Гомера Симпсона :-P – Flafla2

Смежные вопросы