2010-06-01 2 views
0

이 질문의 제목은 아주 자명해야합니다. 같은 목적으로 사용되는 여러 UIImageViews를 사용하는 앱을 만들고 있습니다. 그들은 단지 크기가 다릅니다. 어쨌든, 최선의 해결책은 UIImageView 하위 클래스를 만들고 IB의 subcalsses를 링크하고 거기에서 작업하는 것이라고 결정했습니다. 내 코드는이 더 잘 설명해야 - 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 

는 당연히, 엑스 코드 나에게 오류에 "CGRectIntersectsRect에 대한 호환되지 않는 유형을"했다.

답변

1

당신은하지 뷰의 스스로 그 기능에, 뷰의 프레임을 통과해야합니다 :

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

아를, 대만족입니다. 그건 내 호머 심슨 순간 중 하나 였어 :-P – Flafla2