2011-07-19 6 views
0

UIViewContentModeScaleAspectFitプロパティを使用して、スクロールビューのサイズに合わせてscrollView内のimageViewを拡大/縮小できないようです。大きなUIImageがScroll Viewのフレームに縮尺されていない

- (void)loadView { 
UIImage* image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.moilum.com/images/atomicongallery/setmenu/setmenu1.jpg"]]]; 
imageView = [[UIImageView alloc]initWithImage:image]; 
    imageView.contentMode = UIViewContentModeScaleAspectFit; 
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame]; 
UIScrollView* scrollView = [[UIScrollView alloc]initWithFrame:applicationFrame]; 
[scrollView addSubview:imageView]; 
scrollView.contentSize = image.size; 
scrollView.minimumZoomScale = 0.3; 
scrollView.maximumZoomScale = 3.0; 
scrollView.clipsToBounds = NO; 
scrollView.delegate = self; 
self.view = scrollView; 

}

私もimageView.contentMode = UIViewContentModeScaleAspectFillを試みました。 scrollView.contentmode = UIViewContentModeScaleAspectFillも同様です。すべては!?

に:(

乾杯!

答えて

0

UIScrollViewDelegateで- (UIView *)viewForZoomingInScrollView:(UIScrollView *)sViewメソッドを実装していない場合、UIScrollViewはzoomScaleを調整しません。この

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)sView 
{ 
    NSArray *subViews = [sView subviews]; 
    if([subViews count] > 0){ 
    return [subViews objectAtIndex:0]; 
    } 
    return nil; 
} 

よう

サムシング(しかし、どうやらすべてのデリゲートを設定していないが、あまりにも動作します。)

0

をどのような方法を考え出すように見えるいけないあなたは、私は、これは動作するはずだと思う私のiPadからこのコードを書き、

-(void)loadView 
{ 
     CGRect frame = CGRectMake(0, 0, scrollView.frame.size.width, scrolllView.frame.size.height); 
     imageView = [[UIImageView alloc] initWithFrame:frame]; 
     imageView.image = [UIImage imageNamed:@"yourimage.png"]; 
     imageView.contentMode = UIViewContentModeScaleAspectFit; 
     [scrollView addSubView:imageView]; 
     scrollView.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height); 
} 

を試してみました あなたはどんな問題を抱えているなら、私に教えてください。

幸運。

+0

私はこれを試すものとありがとうございました! –

+0

こんにちはJecht、あなたのコードが動作します!私は問題を発見した。デリゲートをスクロールビューに設定するたびに。 imageviewは設定されたcontentmodeに自身のサイズを変更しません。 scrollview.delegateの何かが、それが起こるのを止めます。また、私はどのようなdoesntがimageviewのサイズを変更された実装viewforScrollViewメソッドができると思う。ありがとう:) –

関連する問題