2011-04-20 85 views
0

我试图找到当用户单击我的图像(在UIImageView中)时如何加载网页。 示例: 如果用户点击徽标谷歌,该应用程序将在www.google.fr上。如何加载带有图像的URL

谢谢:)

回答

1

首先,你需要对ImageView的一个“水龙头”的手势作出反应。

在iOS 3.2及更高版本,这是由UITapGestureRecognizer变得非常容易:

UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)]; 
[self.imageView addGestureRecognizer:recognizer]; 
recognizer.delegate = self; 
[recognizer release]; 

..然后,在自来水的处理程序,您可以打开网址:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.stackoverflow.com"]]; 

参考文献:

UITapGestureRecognizer Class Reference

UIApplication Class Reference/openURL