Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Cannot get a correct screenshot from a view that overrides drawRect #20

Closed
dblock opened this issue Mar 13, 2014 · 10 comments
Closed

Cannot get a correct screenshot from a view that overrides drawRect #20

dblock opened this issue Mar 13, 2014 · 10 comments

Comments

@dblock
Copy link
Contributor

dblock commented Mar 13, 2014

I am not sure what the deal is, but a view with custom drawing is not screen-shotted properly. There's a test in https://github.com/dblock/NAMapKit/blob/tiled-map-view/Demo/DemoTests/NATiledImageMapViewControllerTests.m#L24 that reproduces this.

@dblock
Copy link
Contributor Author

dblock commented Mar 13, 2014

@x2on you seem to have a handle on what's drawn and how (seen #19), maybe you can help with this one?

@x2on
Copy link
Contributor

x2on commented Mar 13, 2014

Does it work with #19 ?

@dblock
Copy link
Contributor Author

dblock commented Mar 13, 2014

It does not work with #19.

I get:

image

I expect something more like:

screenshot 2014-03-13 12 25 00

@dstnbrkr
Copy link
Contributor

@dblock can you post the actual and expected images when you use master?

@dstnbrkr
Copy link
Contributor

I suspect animation is involved in setting up the view.

@dblock
Copy link
Contributor Author

dblock commented Mar 13, 2014

@dstnbrkr They are above (the red dots aren't in the same place because the view centers itself after painting). I have waited for animation for many seconds, the view paints still only after the test finishes. Something is holding it.

@dstnbrkr
Copy link
Contributor

Is the waiting happening on the main thread? That would prevent the animation from completing.

@dstnbrkr
Copy link
Contributor

I'd recommend rendering the view on a background thread, then when that background task completes - take the snapshot. That would prevent the actual test running on the main thread from blocking the animation, which also happens on the main thread.

@dblock
Copy link
Contributor Author

dblock commented Mar 14, 2014

This wasn't working because the view believed it was off-screen. Adding a dummy window fixed the issue, the code is here.

If you think that ios-snapshot-test-case should do something to detect this kind of scenario (after-all views actually repaint explicitly whether they are visible or not), lets leave this open. Otherwise feel free to close.

@dstnbrkr
Copy link
Contributor

I'd say the fact that the test fails in that case is sufficient detection ;-) Testing views via controllers might be prone to this kind of error.

Can probably avoid by testing the view in isolation and doing set up in the test (or moving the view setup into another view object and let the controller load that view).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants