2011-10-26 18 views
5

Estoy escribiendo un lector de PDF usando la biblioteca vfr-reader. Para mostrar dos páginas en formato horizontal, estoy renderizando cada página en su propia vista, luego agrego estas dos vistas a una vista de contenedor, luego agrego vista de contenedor a una vista de desplazamiento. El aumento de tamaño automático de cada vista está configurado en UIViewAutoresizingNone, contentMode es UIViewContentModeRedraw, autoresizingSubviews está establecido en 'NO' para todas las vistas.¿Cómo evitar que el tamaño de UIView cambie de tamaño para ajustarse a la altura de ScrollView (el aumento de tamaño está deshabilitado)?

Pero, de alguna manera, la vista de contenedor se vuelve a escribir para ajustarse a la altura de la vista de desplazamiento, y no sé dónde está sucediendo esto. Me preocupa esto porque, al cambiar el tamaño de la vista del contenedor, su ancho es mayor que el ancho de la pantalla, y no puedo desplazarme a las siguientes dos páginas con un solo deslizamiento (se necesitan dos deslizamientos), lo que apesta. ¿Qué me estoy perdiendo?

EDIT voy a agregar algunos si te ayuda. En el ViewController creo una vista del desfile con las opciones siguientes:

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

Cuando estoy dibujando páginas que estoy añadiendo un UIView a la voluta Vista, que se está iniciando de esta manera:

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; 

y ReaderContentPage se crea de esta manera:

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

¿Ha realizado con éxito el pdf 2página en el paisaje aquí @Spail? – jovhenni19

+0

Sí, pero de una manera un poco retrasada. Espero volver pronto a esta aplicación y hacerlo correctamente. – Spail

Respuesta

1

Hay una propiedad contentMode en UIScrollView, cambiarlo a UIViewContentModeCenter o alguna otra cosa para evitar el cambio de tamaño.

+0

que no ayuda – Spail

+0

¿Puedo ver algún código? –

+0

No estoy seguro de qué código es necesario, pero agregué mucho a mi publicación inicial – Spail

2

En la función updateMinimumMaximumZoom en la clase ReaderContentView:

El cálculo de la zoomscale para ajustarse a la pantalla se hace con una sola vista, pero en el paisaje que debe calcularse forma theContainerView.

intentar sustituir este código

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

con

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

+0

en un modo de página doble para horizontal, para el mismo proyecto (vfr/reader pdf), cómo se puede pasar a la página siguiente cuando se realiza un deslizamiento. Por ejemplo, en la página 1, y tengo 2 páginas que se muestran en theContainerView, cuando hago un deslizamiento quiero cargar la página 3 y 4. Actualmente, cuando hago el barrido, me muestra la página 2 y 3. Cómo lograrlo eso ? –

Cuestiones relacionadas