我正在制作iOS聊天应用。我使用UIBubbleTableView
来显示文本和图像。
现在,我希望图片可以点击,它会移动到另一个视图(人们可以看到它的全尺寸)。但是UIBubbleTableView
似乎不支持它,所以我该如何解决它呢?
这是我在viewDidLoad中的代码:
- (void)viewDidLoad
{
//Something here//
[super viewDidLoad];
NSBubbleData *photoBubble = [NSBubbleData dataWithImage:[UIImage
imageNamed:@"halloween.jpg"] date:[NSDate dateWithTimeIntervalSinceNow:-290]
type:BubbleTypeSomeoneElse];
//something else here//
}
使用这些代码,它只显示图像。
答案 0 :(得分:5)
我知道这不是推荐或理想的方式,但这是我暂时所做的。我可能会回到它并在以后找到一个好方法时“正确”地做到这一点。
对于每个NSBubbleData对象,我向其视图添加一个触摸手势。当用户触摸时,调用touchEventOnImage:
方法。从发件人,您可以获得手势识别器,其视图是由NSBubbleData设置的UIImageView。您可以全屏显示此图像。
这是我使用的代码:
- (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];
}
}
}
我希望这可以帮助你至少取得一些进展。