PDA

View Full Version : UIView contents and hittest issue




99miles
Mar 6, 2009, 09:43 PM
I have a UIView and in initWithFrame I create an image and a label, adding the label to the image view:



label = [[UILabel alloc] init];
label.frame = CGRectMake(20, 20, 80, 80);
[label setTextAlignment:UITextAlignmentCenter];
[label setBackgroundColor:[UIColor colorWithRed:0 green:1 blue:0 alpha:0]];


// load background image
imageObj = [facade imageObj1];
imageView = [[UIImageView alloc] initWithImage: imageObj];
imageView.frame = CGRectMake(20, 20, 80, 80);

[imageView addSubview:label];
[self addSubview:imageView];


I then use the label as a 'hotspot' in a hittest to decide whether or not the view has been touched.

I then create a bunch of instances of this and place them on various parts on the screen. The labels all appear positioned correctly, but the problem is that for the instances at the upper portion of the touch screen my finger has to be higher on the view for the hittest to return true, than for those further down the screen.

I just tried calling setNeedsDisplay after set the views frame, but it didn't help. Any other ideas? Is there something else I need to do to make sure the contents of the view have their positioning updated correctly? As I said, they appear in the correct location, so I'm thinking it's something a little beyond that.

I'd appreciate any thoughts.