Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6754905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:20:12+00:00 2026-05-26T13:20:12+00:00

I have a method for saving the contents of a UIScrollView with a user-supplied

  • 0

I have a method for saving the contents of a UIScrollView with a user-supplied filename.

Everything works fine, except that there is a long delay when the user taps the “Save” button and the method is called. I can’t work out what’s calling the delay, nor find a way to indicate to the user that everything is ok, we have not crashed!

I thought the delay was occurring during the renderInContext, but it seems to be happening a lot earlier, when there is not much else going on.

Here is the troublesome method:

- (void)captureViewImage {

    NSLog(@"captureViewImage called!");

// long delay happens here!

    fileNamer.title = @"Preparing to save...";

    // get user's file name
    NSString *fileName = fileNamer.fileNameField.text;

    // dismiss keyboard
    [fileNamer.fileNameField resignFirstResponder];

    // dismiss modal view
    [self dismissFileNamingFormSheet];

    CGRect oldFrame = mainScrollView.frame;

    // capture off-screen content
    mainScrollView.frame = CGRectMake(0, 0, 1024, 1432);

    // make screenshot
    UIGraphicsBeginImageContext(mainScrollView.bounds.size);
    [mainScrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *screenImg = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    // save screenshot in docs dir
    NSData *pngData = UIImagePNGRepresentation(screenImg);
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [paths objectAtIndex:0];
    [pngData writeToFile:[documentsDir stringByAppendingPathComponent:fileName] 
                 options:NSDataWritingAtomic error:nil];

    // revert scroll view
    mainScrollView.frame = oldFrame;

}

fileNamer is a custom class that throws up a UIModalPresentationFormSheet asking the user to supply a name for the file. It looks like this:

@implementation FileNamingViewController

@synthesize fileNameField, newFileName;


- (id)initWithNibName:(NSString *)nibNameOrNil 
               bundle:(NSBundle *)nibBundleOrNil parent:(TestDriveViewController *) myParent {

    if (self == [super initWithNibName:@"FileNamingViewController" bundle:nil]) {
        UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] 
                                        initWithTitle:@"Save" 
                                        style:UIBarButtonItemStyleDone 
                                        target:myParent 
                                        action:@selector(captureViewImage)];
        self.navigationItem.rightBarButtonItem = rightButton;
        [rightButton release];

        UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] 
                                        initWithTitle:@"Cancel" 
                                        style:UIBarButtonItemStyleBordered 
                                        target:myParent 
                                        action:@selector(dismissFileNamingFormSheet)];
        self.navigationItem.leftBarButtonItem = leftButton;
        [leftButton release];

        self.title = @"Save As?";
    }
    return self;
}


// UITextFieldDelegate

- (void)textFieldDidEndEditing:(UITextField *)textField {
    [fileNameField resignFirstResponder];
}


- (void)viewDidLoad {
    [fileNameField becomeFirstResponder];
    [super viewDidLoad];
}

fileNamer is initialized and released as follows:

- (void)presentFileNamingFormSheet {
    fileNamer = [[FileNamingViewController alloc] 
                 initWithNibName:nil 
                 bundle:nil 
                 parent:self];

    fileNamingNavCtrl = [[UINavigationController alloc]
                        initWithRootViewController:fileNamer];

    fileNamingNavCtrl.modalPresentationStyle = UIModalPresentationFormSheet;

    [self presentModalViewController:fileNamingNavCtrl
                            animated:YES];

    // resize modal form sheet
    fileNamingNavCtrl.view.superview.frame = CGRectMake(0, 0, 540, 115);

    // reposition modal form sheet
    CGPoint position = CGPointMake(self.view.center.x, self.view.center.y - 50);
    fileNamingNavCtrl.view.superview.center = position;
}

- (void)dismissFileNamingFormSheet {
    [fileNamer release];
    [fileNamingNavCtrl release];
    [self dismissModalViewControllerAnimated:YES];  
}

Output from Time Profiler:

Running (Self)      Symbol Name
1109.0ms   37.0%    argb32_image_mark_rgb32
328.0ms   10.9%     blkclr
171.0ms    5.7%     lo_alltraps
134.0ms    4.4%     pmap_enter
116.0ms    3.8%     png_write_find_filter
102.0ms    3.4%     pmap_remove_range
55.0ms    1.8%      pmap_get_mapwindow
47.0ms    1.5%      vm_page_lookup
47.0ms    1.5%      ml_set_interrupts_enabled
43.0ms    1.4%      vm_page_grab
38.0ms    1.2%      OSAddAtomic64
34.0ms    1.1%      hw_lock_to
31.0ms    1.0%      alphaProviderGetBytes
30.0ms    1.0%      hw_lock_unlock
26.0ms    0.8%      png_read_filter_row
25.0ms    0.8%      deflateInit_
23.0ms    0.7%      vm_map_lookup_entry
23.0ms    0.7%      adler32
22.0ms    0.7%      memory_object_recover_named
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:20:13+00:00Added an answer on May 26, 2026 at 1:20 pm

    I found out what was causing this. The image I was saving contained a lot of transparent views. For example, I had a lot of UIButtons which had an alpha value of 0.05 to make them more or less disappear. I didn’t realise I could just set the button type to custom to make it invisible (I created the view along time ago). Once I set everything in my image view to have an alpha value of 1.0, the saving process became a lot quicker.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that where I want to redirect the user back to
I have a method that takes an IQueryable. Is there a LINQ query that
I have method in a class that I need to make sure is only
I have class method that returns a list of employees that I can iterate
I have a method in my Python code that returns a tuple - a
I have a method that can return either a single object or a collection
The problem is that I use the method file _ get _ contents(body.html) in
I have working script that the user completes inputs on a form and when
I have a form that has 2 panels. I'm trying to save the contents
I have a method which takes params object[] such as: void Foo(params object[] items)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.