crop a zoomed image in ImageView inside scrollView

后端 未结 2 1912
灰色年华
灰色年华 2021-02-09 05:47

I already do Lot of efforts from my Side. finally I need help. thanks

Goal : 1) How I fit imageView inside ScrollView

2) How I crop a zoomed Image in inside scro

2条回答
  •  情书的邮戳
    2021-02-09 05:54

    Answer of my own Question : After many efforts i found the answer of both of my questions.

    and it work good for me. I share here, may be it help someone. :)

    1) Fit image View inside Scroll View. I use this link

    - (void)centerScrollViewContents {
    
    CGSize boundsSize = scroll.bounds.size;
    CGRect contentsFrame = self.imageView1.frame;
    
    if (contentsFrame.size.width < boundsSize.width) {
    contentsFrame.origin.x = (boundsSize.width - contentsFrame.size.width) / 2.0f;
    } 
    else {
    contentsFrame.origin.x = 0.0f;
    }
    
    if (contentsFrame.size.height < boundsSize.height) {
        contentsFrame.origin.y = (boundsSize.height - contentsFrame.size.height) / 2.0f;
    } 
    else {
    contentsFrame.origin.y = 0.0f;
    }
    
    self.imageView1.frame = contentsFrame;
    }
    

    2) Crop a zoomed Image in inside scrollView. I use this link

        UIGraphicsBeginImageContext(CGSizeMake(200, 200));
    
        [scroll.layer renderInContext:UIGraphicsGetCurrentContext()];
    
        UIImage *fullScreenshot = UIGraphicsGetImageFromCurrentImageContext();
    
        UIGraphicsEndImageContext();
    
        imageView1.contentMode = UIViewContentModeScaleAspectFill;
    
        UIImageWriteToSavedPhotosAlbum(fullScreenshot, nil, nil, nil);
    
        return fullScreenshot;
    

提交回复
热议问题