How to prevent UIView from resizing to fit ScrollView height (auto shut off)?

I am writing a PDF reader using the vfr-reader library. To display two pages in the landscape, I present each page in my own view, then add these two views to the container view, and then add the container view to the scroll view. In each view, autoresizingMask is set to UIViewAutoresizingNone, contentMode is UIViewContentModeRedraw, autoresizingSubviews is set to "NO" for all views.

But anyway, the container view is autoresist to fit the scroll view height, and I don't know where this happens. I take care of this because when automatically viewing the container, the width becomes greater than the width of the screen, and I cannot scroll pages to the next two pages with one click (two clicks are required), which sucks. What am I missing?

EDIT is going to add some if that helps. In ViewController, I create a scroll view with the following parameters:

theScrollView = [[ReaderScrollView alloc] initWithFrame:viewRect];
theScrollView.scrollsToTop = NO;
theScrollView.pagingEnabled = YES;
theScrollView.delaysContentTouches = NO;
theScrollView.showsVerticalScrollIndicator = NO;
theScrollView.showsHorizontalScrollIndicator = NO;
theScrollView.contentMode = UIViewContentModeRedraw;
theScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
theScrollView.backgroundColor = [UIColor clearColor];
theScrollView.userInteractionEnabled = YES;
theScrollView.autoresizesSubviews = NO;
theScrollView.delegate = self;
[self.view addSubview:theScrollView];

When I draw the pages, I add a UIView to the scroll view, which starts as follows:

if ((self = [super initWithFrame:frame]))
{
    self.autoresizesSubviews = YES;
    self.userInteractionEnabled = YES;
    self.contentMode = UIViewContentModeRedraw;
    self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;       
    self.backgroundColor = [UIColor clearColor];

    theScrollView = [[ReaderScrollView alloc] initWithFrame:self.bounds]; // Not sure about this part - why is the 2nd scroll view added?
// this is the way its done in vfr reader

    theScrollView.scrollsToTop = NO;
    theScrollView.delaysContentTouches = NO;
    theScrollView.showsVerticalScrollIndicator = NO;
    theScrollView.showsHorizontalScrollIndicator = NO;
    theScrollView.contentMode = UIViewContentModeRedraw;
    theScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    theScrollView.backgroundColor = [UIColor clearColor];
    theScrollView.userInteractionEnabled = YES;
    theScrollView.autoresizesSubviews = NO;
    theScrollView.bouncesZoom = YES;
    theScrollView.delegate = self;

    theContentView = [[ReaderContentPage alloc] initWithURL:fileURL page:page password:phrase landscape:(BOOL)isLandscape position:FALSE];
    CGRect viewRect = CGRectZero;
    viewRect.size.width = theContentView.bounds.size.width;
    viewRect.size.height = theContentView.bounds.size.height;    


    if( isLandscape){
        NSLog(@"Landscape detected in content view");
        if (theContentView == NULL)
        {
            theContentView = [[ReaderContentPage alloc] initWithURL:fileURL page:(page+1) password:phrase landscape:(BOOL)isLandscape position:FALSE];
            theContentView2 = NULL;
            viewRect.size.width = theContentView.bounds.size.width;
            viewRect.size.height = theContentView.bounds.size.height;    
        } else {
            if (page == 1)
                theContentView2 = NULL;
            else
                theContentView2 = [[ReaderContentPage alloc] initWithURL:fileURL page:(page+1) password:phrase landscape:(BOOL)isLandscape position:TRUE];
            if (theContentView2 != NULL)
               viewRect.size.width = theContentView.bounds.size.width*2;
        }            

    }       
    if (theContentView != nil) // Must have a valid and initialized content view
    {

        theContainerView = [[UIView alloc] initWithFrame:viewRect];


        theContainerView.autoresizesSubviews = NO;
        theContainerView.userInteractionEnabled = NO;
        theContainerView.contentMode = UIViewContentModeRedraw;            
        theContainerView.autoresizingMask = UIViewAutoresizingNone;
        theContainerView.backgroundColor = [UIColor whiteColor];


        theScrollView.contentSize = theContentView.bounds.size; // Content size same as view size


        theScrollView.contentOffset = CGPointMake((0.0f - CONTENT_INSET), (0.0f - CONTENT_INSET));
        theScrollView.contentInset = UIEdgeInsetsMake(CONTENT_INSET, CONTENT_INSET, CONTENT_INSET, CONTENT_INSET);

        theThumbView = [[ReaderContentThumb alloc] initWithFrame:theContentView.bounds]; // Page thumb view           

        [theContainerView addSubview:theThumbView]; // Add the thumb view to the container view

        [theContainerView addSubview:theContentView]; // Add the content view to the container view

        if(( isLandscape) && (theContentView2 != NULL)){            
             [theContainerView addSubview:theContentView2]; // Add the content view to the container view

        }           



        [theScrollView addSubview:theContainerView]; // Add the container view to the scroll view

        [self updateMinimumMaximumZoom]; // Update the minimum and maximum zoom scales

        theScrollView.zoomScale = theScrollView.minimumZoomScale; // Zoom to fit
    }

    [self addSubview:theScrollView]; // Add the scroll view to the parent container view   

    [theScrollView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:NULL];

    self.tag = page; // Tag the view with the page number
}

return self;

And the ReaderContentPage is created this way:

if ((self = [super initWithFrame:frame]))
    {
        self.autoresizesSubviews = NO;

        self.userInteractionEnabled = NO;
        self.clearsContextBeforeDrawing = NO;
        self.contentMode = UIViewContentModeRedraw;     
        self.autoresizingMask = UIViewAutoresizingNone;
        self.backgroundColor = [UIColor clearColor];

        view = self; // Return self
    }
+5
source share
2 answers

In function updateMinimumMaximumZoomin class ReaderContentView:

, ContainerView.

CGFloat zoomScale = ZoomScaleThatFits(targetRect.size, theContentView.bounds.size);

CGFloat zoomScale = ZoomScaleThatFits(targetRect.size, theContainerView.bounds.size);

+2

UIScrollView contentMode, UIViewContentModeCenter - , .

+1

All Articles