2011-10-26 7 views
5

Piszę czytnik plików PDF za pomocą biblioteki vfr-reader. Aby wyświetlić dwie strony w krajobrazie, renderuję każdą stronę do jej własnego widoku, następnie dodaj te dwa widoki do widoku kontenera, a następnie dodaj widok kontenera do widoku przewijania. Dla każdej z nich ustawiona jest opcja UIViewAutoresizingNone, contentMode to UIViewContentModeRedraw, autouzupełnianieWyświetlone jest ustawione na "NIE" dla wszystkich widoków.Jak zapobiec zmianie rozmiaru UIView w celu dopasowania do wysokości ScrollView (autoretykowanie wyłączone)?

Jednak w pewnym sensie widok kontenera jest automatycznie dostosowywany do rozmiaru przewijania i nie wiem, gdzie to się dzieje. Dbam o to, ponieważ podczas autorezoryzowania widoku kontenera jego szerokość staje się większa niż szerokość ekranu i nie mogę przewijać do następnych dwóch stron jednym suwakiem (potrzebne są dwa przesuwania), co jest do bani. czego mi brakuje?

EDIT Dodam niektóre, jeśli to pomoże. W ViewController utworzyć przewijania widoku z następujących opcji:

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]; 

Kiedy Rysuję stron Dodaję się UIView do przewijania widoku, który jest zainicjowany w ten sposób:

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; 

i ReaderContentPage jest tworzony w ten sposób:

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 
    } 
+0

Czy z powodzeniem zrobić pdf 2Strona krajobrazu tutaj @Spail? – jovhenni19

+0

Tak, ale w nieco uporczywy sposób. Mam nadzieję, że wkrótce powrócę do tej aplikacji i zrobię to poprawnie. – Spail

Odpowiedz

1

Istnieje właściwość contentMode w UIScrollView, zmień go na UIViewContentModeCenter lub coś innego, aby zapobiec zmianie rozmiaru.

+0

która nie pomaga – Spail

+0

Czy mogę zobaczyć kod? –

+0

Nie jestem pewien, który kod jest potrzebny, ale dodałem wiele do mojego pierwszego posta. – Spail

2

W funkcji updateMinimumMaximumZoom w klasie ReaderContentView:

Obliczenie zoomscale celu dopasowania do ekranu odbywa się z jednego widoku, ale w krajobrazie powinna być obliczona formularz theContainerView.

Spróbuj zastąpić ten kod

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

z

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

+0

w trybie podwójnej strony dla krajobrazu, dla tego samego projektu (vfr/reader pdf), w jaki sposób udaje się przejść do następnej strony po przesunięciu. Na przykład jestem na stronie 1, i mam 2 strony pokazujące wContainerView, kiedy robię przesunięcie, chcę załadować strony 3 i 4. Obecnie, gdy wykonuję przesunięcie, pokazuje mi stronę 2 i 3. Jak osiągnąć to ? –

Powiązane problemy