Capture Scrollview's contents

Discussion in 'iOS Programming' started by nsnarvekar, Jan 15, 2010.

  1. nsnarvekar macrumors newbie

    Joined:
    Jun 17, 2009
    #1
    Hello,

    I have one scrollview which contains view which includes the imageview and label.

    I want to Pinch in and out that view with the imageview and label.
    I am doing it properly. But I also want to to capture the contents of view and send it through mail with the expanded size

    Code:
    UIGraphicsBeginImageContext(ContainerView.bounds.size);
    	
    	[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    	
    	UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    	
    	UIGraphicsEndImageContext();
    
    ContainerView - name of the view
    I also replace this ContainerView with the ScrollView.Contentsize
    Still not getting any success.:confused:

    Any suggestion or code is appreciated

    Please help me.
    Thanks
     
  2. NasserAE macrumors newbie

    Joined:
    Jan 29, 2009
    #2
    Maybe this is too late but I had the same problem and solved it. I though I can help by posting the solution here. Just expand your container view before you start any thing. For example if you want to capture the whole scrollview, even off display content, you will need to size your scroll view to match your content size like this:

    Code:
    self.scrollView.frame = CGRectMake(0, 44, 768, 1024);
    And when you are done drawing make sure to resize your scrollview back:

    Code:
    self.scrollView.frame = CGRectMake(0, 44, self.view.frame.size.width, self.view.frame.size.height);
    This was the code I used in my iPad app to capture the scroll view when the device is in landscape mode. The "44" offset was to accommodate for the toolbar at the top. I think you get the idea.
     

Share This Page