2012-07-12 4 views
0

줌 기능을 사용하려면 UIImageView가있는 UIScrollView가 있습니다.UIImageView가 부분적으로 화면에 표시되는 UIScrollView

문제는 이제 scrollView가 전체 화면 (navigationBar 제외)으로 표시되어야하지만 이상한 "오프셋"으로 표시된다는 점입니다. http://i47.tinypic.com/25pprg3.png

빨간색 사각형 이미지가 전체보기를해야하면서 이상한, 즉 표시되는 것 오프셋하지만 그렇지 않다 :

이미지가 1000 개 이상의 단어를 설명 인해 것이 여기 있습니다. 보시다시피, 대신 잘리고 있습니다.

프레임, 테두리 등을 변경했지만 동일한 결과를 보았습니다. 하지만 성공, 나는 모든 노력을

- (void)viewDidLoad 
{ [super viewDidLoad]; 

    self.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor]; 

    imageScrollView.bouncesZoom = YES; 
    imageScrollView.delegate = self; 
    imageScrollView.clipsToBounds = NO; // If set to yes, the image would be like the screen above 
    imageView = [[UIImageView alloc] init]; 
    imageView.clipsToBounds = YES; 


    imageScrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin); 

    //activity indicator 
    UIActivityIndicatorView *activityIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease]; 
    activityIndicator.hidesWhenStopped = YES; 
    activityIndicator.hidden = NO; 
    activityIndicator.center = CGPointMake(self.imageView.frame.size.width /2, self.imageView.frame.size.height/2); 
    [activityIndicator startAnimating]; 


    [imageView setImageWithURL:[NSURL URLWithString:tipImageString] 
       placeholderImage:nil options:SDWebImageProgressiveDownload 
         success:^(UIImage *image) { [activityIndicator stopAnimating];[activityIndicator removeFromSuperview]; } 
         failure:^(NSError *error) { [activityIndicator stopAnimating];[activityIndicator removeFromSuperview]; }]; 
    [imageView addSubview:activityIndicator]; 

    imageView.userInteractionEnabled = YES; 
    imageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin); 
    imageView.center = [[imageScrollView window] center]; 
    imageView.contentMode = UIViewContentModeScaleAspectFit; 
    [imageScrollView setContentMode:UIViewContentModeScaleAspectFit]; 
    [imageScrollView addSubview:imageView]; 
    imageScrollView.contentSize = self.imageView.image.size;  
    imageScrollView.decelerationRate = UIScrollViewDecelerationRateFast; 

    CGSize boundsSize = self.imageScrollView.bounds.size; 
    imageView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); 
    CGRect frameToCenter = imageView.frame; 

    // center horizontally 
    if (frameToCenter.size.width < boundsSize.width) 
     frameToCenter.origin.x = (boundsSize.width - frameToCenter.size.width)/2; 
    else 
     frameToCenter.origin.x = 0; 

    // center vertically 
    if (frameToCenter.size.height < boundsSize.height) 
     frameToCenter.origin.y = (boundsSize.height - frameToCenter.size.height)/2; 
    else 
     frameToCenter.origin.y = 0; 

    imageView.frame = frameToCenter; 

    // calculate minimum scale to perfectly fit image width, and begin at that scale 
    float minimumScale = 0.50;//[imageScrollView frame].size.width/[imageView frame].size.width; 
    imageScrollView.maximumZoomScale = 5.0; 
    imageScrollView.minimumZoomScale = minimumScale; 
    imageScrollView.zoomScale = minimumScale; 
    [imageScrollView setContentMode:UIViewContentModeScaleAspectFit]; 
    [imageView sizeToFit]; 

    [imageScrollView setContentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height)]; 

} 

:

여기 내 코드입니다!

프레임이있는 것으로 생각하지만 무엇을 알아 내지 못합니다.

도움을 주신 경우

답변

2

@Pheel 기쁜 당신은 이미지의 CGAffineTransformMakeRotation 때문에 그것을 발견 할 수 있습니다. 이로 인해 좌표가 변경 될 수 있습니다.

+0

). imageScrollView 프레임을 다시 설정해야했습니다! – Phillip

0

이미지 해상도를 변경하십시오. 또한 스크롤 뷰를 시각적으로 배치 한 다음 Interface Builder에 이미지 뷰를 배치 해 보았습니까? 그 일을 한 후에는있는 viewDidLoad 등의 방법으로 초기화 할 수

+0

여러 이미지 (더 낮은 해상도)를 사용해도 동일한 결과가 나타납니다. 네, IB에 연결된 모든 것은 개선되지 않았습니다. – Phillip

+0

속성 검사기는 어떻습니까? –

+0

모든 것이 괜찮습니다. scrollView는 전체 화면 (전체보기)로 표시되도록 설정되었습니다. – Phillip

0

왜 그냥하지 않습니다

... set-up imageView... 
imageView.frame = imageScrollView.bounds; 
imageView.contentMode = UIViewContentModeScaleAspectFit; 
[imageScrollView addSubview:imageView]; 

당신은 중복 또는 (당신의 방법에 누적 효과가 많은 코드를 frame/center, contentMode, contentSize ...)의 여러 연속적인 변경으로 인해 무엇이 무엇이 발생하는지 알기가 어렵습니다 (아마도 스크롤 뷰가 이미지 뷰를 잘라내는데, 그 중심은 슈퍼 뷰가 아닌 윈도우 좌표를 기반으로합니다). 좌표,하지만 마침내, 당신은 프레임을 재정의하기 때문에 ...). 당신은 정확히 무엇을 원 하느냐와 시작하는 구성 (예를 들어 스크롤보기 프레임은 무엇입니까?)에 따라 좀 더 간단한 코드로 처음부터 시작해야합니다.

+0

그럼 코드가 완벽하게 작동하는 다른 프로젝트에서 코드를 가져 왔습니다. 나는 왜 그것이 현재 작동하지 않는지 (또는 더 나은 것은 아닌지, 왜 그것이 이전 프로젝트에서와 같은지는 알 수 없다). 나는 당신이 한 일을하려고 노력할 것이지만, 이미지를보기의 완벽한 중심에 두는 약간의 조정이 있습니다 (즉, – Phillip

관련 문제