2009-09-15 6 views
1

Dans une classe qui est conforme à UIApplicationDelegate et UIScrollViewDelegate je l'ai fait ce qui suit dans:Est-ce un bogue de zoom dans UIScrollView?

- (void)applicationDidFinishLaunching:(UIApplication *)application { 


// Created an instance of UIScrollView to house a horizontal strip - along the x-axis - of kNumberOfPages UIViews: 

    scrollView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame]; 


// Make self the delegate 

    scrollView.delegate = self; 


// Set content size to the cumulative width of all UIViews contained 

    scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, scrollView.frame.size.height); 


// Zoom range is from a min of the width of the scrollView to a max of 2 * scrollView.contentSize 

    scrollView.minimumZoomScale = scrollView.frame.size.width/scrollView.contentSize.width; 
    scrollView.maximumZoomScale = 2 * scrollView.contentSize; 


// A subclass of UIView will be the container for the horizontal strip of UIViews 

    containerView = [[ConstrainedView alloc] initWithFrame:CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height)]; 


// The only difference betrween ConstrainedView and UIView is this overloaded method that constrains zooming to only the x-axis 


- (void)setTransform:(CGAffineTransform)newValue { 


    // Scale along the y-axis only 
    CGAffineTransform constrainedTransform = CGAffineTransformScale(CGAffineTransformIdentity, newValue.a, 1.0); 


    [super setTransform:constrainedTransform]; 


} 


// Fill the container view with UIViews as subviews 
CGFloat horizontalOffsetX = 0.0; 
for (int i = 1; i <= kNumberOfPages; i++) { 

    CGRect frame = CGRectMake(horizontalOffsetX, 0.0, scrollView.frame.size.width, scrollView.frame.size.height); 
    UIView *v = [[[UIView alloc] initWithFrame:frame] autorelease]; 


// paint the background of each UIView a random color. 

    v.backgroundColor = [UIColor colorWithRed:randomRed green:randomGreen blue:randomBlue alpha:1.0]; 
    [containerView addSubview:v]; 

    horizontalOffsetX += v.bounds.size.width; 

} // for (kNumberOfPages) 



// insert the container view as a subview of scrollView 
    [scrollView addSubview:containerView]; 

    [window addSubview:scrollView]; 
    [window makeKeyAndVisible]; 

} 

semble assez docile, non? Voici l'étrangeté. Zoom avant - grossissant - fonctionne bien. Cependant, au fur et à mesure que j'effectue un zoom, la résistance, la gigue et la lenteur augmentent, comme si je traînais à travers la mélasse durcie alors que j'essayais d'approcher complètement le zoom. Il est presque impossible d'écraser les N UIViews afin qu'ils apparaissent tous dans les limites des cadres UIScrollView. Très étrange.

Quelqu'un peut-il expliquer ce qui se passe et s'il s'agit d'un bug?

Cheers,

Doug

+0

J'ai remarqué cette ligne 'scrollView.maximumZoomScale = 2 * scrollView.contentSize,' semble incorrecte? Je pense que ça devrait être 'scrollView.maximumZoomScale = 2;' –

Répondre

1

MISE À JOUR

Mon approche ne semble travailler avec la mise en garde suivante. Il semble y avoir un problème de condition aux limites ici.

Cela fonctionne:

scrollView.minimumZoomScale = (scrollView.frame.size.width/scrollView.contentSize.width)/0,99;

Ce bloque - plante - l'application:

scrollView.minimumZoomScale = scrollView.frame.size.width/scrollView.contentSize.width;

Tant que la largeur de scrollView dépasse la largeur du contenu - indépendamment du zoom différentiel - l'application semble fonctionner correctement.

Je peux facilement contourner cette limitation mineure. Cool.

Cheers,

Doug