2010-06-01 54 views
0

這個問題的標題應該很自我解釋。我正在製作一個涉及多個UIImageView的應用程序,這些應用程序可用於相同的目的。它們僅僅是不同的尺寸。無論如何,我決定最好的解決方案是製作UIImageView子類,鏈接IB中的子類,並從那裏開始工作。我的代碼應該解釋這更好 -與CGRectIntersectsRect的UIImageView子類 - 幫助!



#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 

不出所料,Xcode中給了我一個「不兼容的類型CGRectIntersectsRect」的錯誤。

回答

1

你必須通過視圖的框架,而不是視圖的本身到功能:

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

哦,真不錯。那是我的荷馬辛普森時刻之一:-P – Flafla2 2010-06-01 22:08:23