Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image insides UIBubbleTableView

I am making an iOS chat app. I use UIBubbleTableView to display texts and images.

Now ,I want the image can click and it will move to another view (which people can see it in full size). But UIBubbleTableView seems doesn't support it, so how can i fix it?

Here is my code in viewDidLoad:

- (void)viewDidLoad
{
    //Something here//
    [super viewDidLoad];
    NSBubbleData *photoBubble = [NSBubbleData dataWithImage:[UIImage         
    imageNamed:@"halloween.jpg"] date:[NSDate dateWithTimeIntervalSinceNow:-290]     
    type:BubbleTypeSomeoneElse];
    //something else here//
}

With these codes it just shows the image.

like image 714
jackiviet Avatar asked Jun 27 '26 15:06

jackiviet


1 Answers

I know this isn't the recommended or ideal way to do it, but this is what I have done for the time being. I will likely come back to it and do it "correctly" later when I find a good way.

For each NSBubbleData object, I add a touch gesture to it's view. When the user touches, the touchEventOnImage: method is called. From sender, you can get the gesture recognizer, whose view is that of the UIImageView set by the NSBubbleData. You can display this image full screen.

This is the code I used:

- (void)addTouchGestureToBubble:(NSBubbleData *)oBubbleData
{
    UITapGestureRecognizer * tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchEventOnImage:)];
    [tapRecognizer setNumberOfTouchesRequired:1];
    //Don't forget to set the userInteractionEnabled to YES, by default It's NO.
    oBubbleData.view.userInteractionEnabled = YES;
    [oBubbleData.view addGestureRecognizer:tapRecognizer];
}

- (void)touchEventOnImage:(id)sender
{
    if( [sender isKindOfClass:[UIGestureRecognizer class]] )
    {
        UIGestureRecognizer * recognizer = (UIGestureRecognizer *)sender;

        if( [recognizer.view isKindOfClass:[UIImageView class]] )
        {
            UIImageView * imageView = [[UIImageView alloc] initWithImage:((UIImageView *)recognizer.view).image];
            imageView.contentMode = UIViewContentModeScaleAspectFit;
            imageView.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
            imageView.backgroundColor = [UIColor blackColor];
            // Remove the corner radius applied in the NSBubbleData class.
            imageView.layer.cornerRadius = 0.0;

            UIViewController * vc = [[UIViewController alloc] init];
            vc.view = imageView;
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}

I hope this helps you at least make some progress.

like image 81
thephatp Avatar answered Jun 29 '26 04:06

thephatp