Mohammad Salman
Mohammad Salman

Reputation: 76

UIView Becomes Visible Delegate

When we change the hidden property of a view than is there a way to identify the exact point where view becomes completely visible or hidden i.e drawing operation gets completed.

In my app I have to take the screenshot once the view gets hide, currently I have added a delay of 330ms just to make sure that the view is completely hidden, I want to get rid of this arbitrary delay.

I have already tried couple of things like KVO on view hidden property, I subclass UIView class and try to utilize viewDidMoveToSuperView delegate also, but all these things does not guaranteed that the view drawing has been completed.

Upvotes: 0

Views: 345

Answers (1)

Ben Kennedy
Ben Kennedy

Reputation: 288

Two ideas come immediately to mind:

  1. schedule a block on the main queue which will presumably be called after the next iteration of the run loop (by which time view redrawing should have occurred).

    dispatch_sync(dispatch_get_main_queue(), ^{
        // take your snapshot
    });
    
  2. manipulate the view's opacity in an animation block (hidden cannot be animated but alpha can) and employ the completion handler.

    [UIView animateWithDuration:0 animations:^{
        view.alpha = 0;
    } completion:^(BOOL finished) {
        // take your snapshot
    }];
    

Upvotes: 1

Related Questions