I have a tabular view. Some cells may have images, and I add these images to cells through a UIImageView. These images react and open a new view controller if the user deletes it (and not the cell). Images have different sizes.
I added a UITapGestureRecognizer to the UIImageView, but it acts weirdly. I thought that the entire area of ββthe imageView would respond to gestures, but I see only some smaller areas, and in all images this area is located differently.
Here is the code from the init cell:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier UIImageView *thumbnailImageView = [[[UIImageView alloc] init] autorelease]; thumbnailImageView.tag = CELL_THUMBNAIL_TAG; thumbnailImageView.userInteractionEnabled = YES; [self.contentView addSubview:thumbnailImageView]; UITapGestureRecognizer *pictureTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handlePictureTap:)]; [thumbnailImageView addGestureRecognizer:pictureTap]; [pictureTap release];
All cells with images are displayed correctly in different orientations. The location of images and texts inside cells is performed using the layoutSubviews method:
- (void)layoutSubviews if (thumbnail) { CGRect thumbnailFrame = CGRectMake(contentOrigin.x, contentOrigin.y, thumbnail.size.width, thumbnail.size.height); thumbnailImageView = (UIImageView *)[self.contentView viewWithTag:CELL_THUMBNAIL_TAG]; thumbnailImageView.frame = thumbnailFrame; thumbnailImageView.image = thumbnail;
}
In tableView: cellForRowAtIndexPath: method I just pass all the necessary data to the cell, so the whole configuration goes to layoutSubviews
Could you help me determine why the area that responds to the click gesture is randomly determined and strange for all images, despite the fact that all the content is displayed correctly?
source share