The start of presentation is delayed a few seconds #35

UniSIM opened this Issue Mar 15, 2013 · 7 comments


None yet
4 participants

UniSIM commented Mar 15, 2013

When I try to present a simple semi view from a quite complicated viewcontroller which contains a lot of thumbnails, the start of the presentation is delayed for quite a few seconds even on my iPhone 5. What's the cause and how can I fix it?

I added KNSemiModalOptionKeys.traverseParentHierarchy : @(NO), which helps a little, but still can see 1-2 seconds lag.



kentnguyen commented Mar 15, 2013

There's nothing can be done about that. The library renders the entire
screen so it is not designed for complicated viewcontroller. unless u know
how to hack it by preparing the screenshot ahead of presenting the modal.

Kent Nguyen

UniSIM commented Mar 15, 2013

I found that change the line:
UIGraphicsBeginImageContextWithOptions(target.bounds.size, YES, [[UIScreen mainScreen] scale]);
replace scale with 1 or even 0.5, it speeds up a lot.
Can you make this an option as well?

Another way to enhance is that when pushBackParent is false, should not capture the screen at all, just like this:

        overlay.layer.opacity = 0.1;
        // Take screenshot and scale

        [target addSubview:overlay];

        // Dismiss button (if allow)
        if(![[self ym_optionOrDefaultForKey:KNSemiModalOptionKeys.disableCancel] boolValue]) {
            // Don't use UITapGestureRecognizer to avoid complex handling
            UIButton * dismissButton = [UIButton buttonWithType:UIButtonTypeCustom];
            [dismissButton addTarget:self action:@selector(dismissSemiModalView) forControlEvents:UIControlEventTouchUpInside];
            dismissButton.backgroundColor = [UIColor clearColor];
            dismissButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
            dismissButton.frame = overlayFrame;
            dismissButton.tag = kSemiModalDismissButtonTag;
            [overlay addSubview:dismissButton];

        // Begin overlay animation
        UIImageView *ss;
        if ([[self ym_optionOrDefaultForKey:KNSemiModalOptionKeys.pushParentBack] boolValue]) {
            ss = [self kn_addOrUpdateParentScreenshotInView:overlay];
            [ss.layer addAnimation:[self animationGroupForward:YES] forKey:@"pushedBackAnimation"];
        NSTimeInterval duration = [[self ym_optionOrDefaultForKey:KNSemiModalOptionKeys.animationDuration] doubleValue];
        if ([[self ym_optionOrDefaultForKey:KNSemiModalOptionKeys.pushParentBack] boolValue]) {
            [UIView animateWithDuration:duration animations:^{
                ss.alpha = [[self ym_optionOrDefaultForKey:KNSemiModalOptionKeys.parentAlpha] floatValue];

I would set scale here to 0.f

UIGraphicsBeginImageContextWithOptions(target.bounds.size, YES, 0.f);

That way it matches the scale of the device. Not sure how relevant this is, but its good practice to do so.


kentnguyen commented Mar 21, 2013

@bopeus why is it better than [[UIScreen mainScreen] scale] ?

To be honest I don't know if it really makes a difference. Personally I find it easier to read, less to write. And Apple's docs for UIGraphicsBeginImageContextWithOptions say to pass 0 for automatic scale:

"The scale factor to apply to the bitmap. If you specify a value of 0.0, the scale factor is set to the scale factor of the device’s main screen."


kentnguyen commented Mar 21, 2013

@bopeus : understood. But i'll keep it the way it is, more explicit.

@benxiong Can you make a pull request?

kentnguyen closed this Apr 28, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment