2010-11-01 4 views
0

Dans mon application, j'ai utilisé un UIImageView dans UIScrollView et j'ai utilisé le code pour cela.Problème lors du zoom sur UIScrollView?

- (void)viewDidLoad 

{ 

scrollV.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height); 

    [super viewDidLoad]; 

} 

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView 

{ 

    return imageView; 
} 

le code fonctionne bien, mais quand je plaçant UIButton sur le imageView de ScrollView et après i zoom le scrollV, le zoom imageView parfaitement selon ScrollView mais UIButton et ne pas être zoomée.

Je veux quand je zoome l'imageview, les boutons que j'ai placés sur imageView également être zoom par rapport à l'imageView agrandi.

+0

@Jacob Relkin, avez-vous des idées à ce sujet? – Tirth

Répondre

0

Je suis succès pour trouver la solution de question.I ci-dessus écrit le pour que,

- (void)viewDidLoad 

{ 

    bgViewOfImage.contentStretch = CGRectMake(ImageView.frame.origin.x, ImageView.frame.origin.y, ImageView.frame.size.width, ImageView.frame.size.height); 
    scrollV.contentSize = CGSizeMake(bgViewOfImage.frame.size.width, bgViewOfImage.frame.size.height); 
    [super viewDidLoad]; 
} 


- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView 

{ 

    return bgViewOfImage; 
} 

je créer une hiérarchie insertion d'un UIView sur la vue principale puis Je fais glisser d'autres contrôles comme UIImageview et UIButtons sur lui. Maintenant, il fonctionne parfaitement et de zoomer chaque contrôle.

1

Créez une instance proxy UIView en tant que sous-vue scrollview et placez tous les éléments de l'interface utilisateur que vous souhaitez agrandir. Ensuite, retournez ce point de vue de la méthode viewForZoomingInScrollView

0
CGSize imageView = [photo size]; 
    UIScrollView *scrollView = (UIScrollView *)[self view]; 
    [scrollView setDelegate:self]; 
    [scrollView setContentSize:photoSize]; 
    [scrollView setBackgroundColor:[UIColor blackColor]]; 
    [scrollView setShowsHorizontalScrollIndicator:NO]; 
    [scrollView setShowsVerticalScrollIndicator:NO]; 

    // Create the image view. 
    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, photoSize.width, photoSize.height)]; 
    [imageView setImage:photo]; 
    [scrollView addSubview:imageView]; 

    // Configure zooming. 
    CGSize screenSize = [[UIScreen mainScreen] bounds].size; 
    CGFloat widthRatio = screenSize.width/photoSize.width; 
    CGFloat heightRatio = screenSize.height/photoSize.height; 
    CGFloat initialZoom = (widthRatio > heightRatio) ? heightRatio : widthRatio; 
    [scrollView setMaximumZoomScale:3.0]; 
    [scrollView setMinimumZoomScale:initialZoom]; 
    [scrollView setZoomScale:initialZoom]; 
    [scrollView setBouncesZoom:YES]; 

    // Center the photo. 
    CGFloat topInset = (screenSize.height - photoSize.height * initialZoom)/2.0; 
    if (topInset > 0.0) 
    { 
     [scrollView setContentInset:UIEdgeInsetsMake(topInset - 44.0, 0.0, 0.0, 0.0)]; 
    } 
} 

#pragma mark - 
#pragma mark UIScrollViewDelegate 

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView 
{ 
    return imageView; 
} 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 
    CGSize screenSize = [[UIScreen mainScreen] bounds].size; 
    CGSize photoSize = [photo size]; 
    CGFloat topInset = (screenSize.height - photoSize.height * [scrollView zoomScale])/2.0; 
    if (topInset < 0.0) 
    { 
     topInset = 0.0; 
    } 

    [scrollView setContentInset:UIEdgeInsetsMake(topInset, 0.0, -topInset, 0.0)]; 
} 
+0

Vous devriez réorganiser votre code pour la lecture humaine. – AechoLiu

Questions connexes