2012-02-08 16 views
0

ズーム機能をUIImageに追加したいと思っており、UIWebviewに埋め込むのが最善の方法だと思います。誰かがこれを達成するのを手伝ってくれますか?UIWebViewをプログラムによってUIImageViewに追加する

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

// image 
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 70, IMGSIZE.width, IMGSIZE.height)]; 
[self.imageView setClipsToBounds:YES]; 
self.imageView.layer.borderColor = kITBarTint.CGColor; 
self.imageView.layer.borderWidth = 1.0; 
self.imageView.layer.cornerRadius = 15.0; 
self.imageView.layer.shadowColor = [UIColor blackColor].CGColor; 
self.imageView.layer.shadowOffset = CGSizeMake(5, 5); 
self.imageView.layer.shadowRadius = 10; 

[self.controller.view addSubview:self.imageView]; 

// activity indicator 
CGRect frame = CGRectMake(roundf(IMGSIZE.width/2) + self.imageView.frame.origin.x, roundf(IMGSIZE.height /2) + self.imageView.frame.origin.y, 0, 0); 
_activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
[_activityIndicator setFrame:frame]; 
[_activityIndicator startAnimating]; 
[self.controller.view addSubview:_activityIndicator]; 


} 
+0

を使用してみてください - この[質問](http://stackoverflow.com/questions/2685161/iphone-uiscrollview-and-uiimageview-settingを参照してください-initial-zoom) – Jason

+0

スクロールビューを使用してズームし、上記のコードにどのように適用できますか? – CraigBellamy

+0

私のコードを試してください、それは私のためにうまくいく!! :D – iProRage

答えて

1

てみてください!

そして、私はUIScrollViewのを使用してより良いアプローチだと思うUIScrollViewの

1

さらにUIImageviewを使用する必要はありません。

ローカルファイルの場合、file://はURLとして使用します。ファイル幅のパスを取得することができます:

NSString *path = [[NSBundle mainBundle] pathForResource:@"myimage" ofType:@"jpg"]; 

WebViewの場合、単純にHtmlコードをStringとして作成します。

[webView loadHTMLString: [NSString stringWithFormat:@"<html><head></head><body><img src=\"file://%@\"></body></html>",path] baseURL:nil]; 

HTML文字列の内部では、サイジングや配置にCSSを使用することもできます。

scrollView.minimumZoomScale = 0.4; 
scrollView.maximumZoomScale = 4.0; 
scrollView.delegate = self; 
[scrollView setZoomScale:scroll.minimumZoomScale]; 

は、この情報がお役に立てば幸いあなたviewDidLoad方法、これを追加すること