2011-04-20 87 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