UIImageView子类与CGRectIntersectsRect - 帮助!

时间:2010-06-01 21:33:30

标签: iphone uiimageview subclass

这个问题的标题应该是非常自我解释的。我正在制作一个涉及多个UIImageViews的应用程序,它们具有相同的用途。它们只是不同的尺寸。无论如何,我认为最好的解决方案是制作UIImageView子类,链接IB中的子类,然后从那里开始工作。我的代码应该更好地解释 -



#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 个答案:

答案 0 :(得分:1)

您必须将视图的框架,而不是视图本身传递给该函数:

CGRectIntersectsRect(doctorview.frame, groundview.frame)