我知道这不是推荐或理想的方法,但这是我暂时所做的。当我找到一个好方法时,我可能会回到它并“正确”地做它。
对于每个 NSBubbleData 对象,我在其视图中添加了一个触摸手势。当用户触摸时,该touchEventOnImage:
方法被调用。从 sender 那里可以得到手势识别器,它的视图是 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];
}
}
}
我希望这可以帮助你至少取得一些进展。