Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves issue #5 #7

Merged
merged 9 commits into from
May 28, 2014
Merged

Resolves issue #5 #7

merged 9 commits into from
May 28, 2014

Conversation

obj-p
Copy link
Contributor

@obj-p obj-p commented May 25, 2014

Added to .gitignore.
Added sizeForDeviceOrientation method.
psdRepresentationForScreen can create psd document with landscape dimensions.
Referred to screen size in context and rendered sublayer with transformation. (Perhaps there's a better way to do it).

@vpdn
Copy link
Owner

vpdn commented May 25, 2014

Issue #5 is high on the priority list, thanks for taking this up!

@vpdn vpdn mentioned this pull request May 25, 2014
Changed sizeForDevice... to sizeForInterface (language)
Added bool method
@obj-p
Copy link
Contributor Author

obj-p commented May 25, 2014

I agree about the sublayers thing. That was pretty hacky. I changed it to only apply transforms to the context when the interface is in landscape. I noticed the status bar layers already rendered correctly when in landscape and gets messed up when applying the transforms to the context so I also check the layer transform to make sure it needs to be applied to the context.

I also modified the methods I added just to reflect more concise language.

Instead of checking for transform identity now
check if the layer has the status bar as a delegate.
// if interface is in landscape, apply transforms to context for layers not in the status bar
if (![self isInterfaceInPortrait] && ![layer.delegate isKindOfClass:NSClassFromString(@"UIStatusBarWindow")]) {
CGContextTranslateCTM(ctx, 0, size.height);
CGContextRotateCTM(ctx, -M_PI_2);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not quite right yet. This works for device orientation left, but fails if the device is rotated to the right. Since rotated the same way independent of the device orientation, it will show the UI upside down for one of the device rotations?

layershots_wrong_translation

Check for both orientations could be done like so:

    if (orientation==UIInterfaceOrientationLandscapeLeft) {
        CGContextTranslateCTM(ctx, size.width, 0);
        CGContextRotateCTM(ctx, M_PI_2);
    } else {
        CGContextTranslateCTM(ctx, 0, size.height);
        CGContextRotateCTM(ctx, -M_PI_2);
    }

The UI seems to be flipped (see how the shadow is on the top right instead of bottom right). I don't really understand why though. Will try look into it in more detail tonight, but maybe you already have guess or some solution up your sleeve.

screenshot 2014-05-26 18 34 55

(Top view: PSD, bottom view: Simulator)

@obj-p
Copy link
Contributor Author

obj-p commented May 26, 2014

Yea i'm still trying to wrap my head around it too. i can get it to render correctly if i don't bother to transform the context and just render the sublayer.

[layer.sublayers[0] renderInContext:ctx];

layershots

I'd like to figure out why this works and then abstract it out.

@vpdn
Copy link
Owner

vpdn commented May 27, 2014

I've played around a bit more. It seems that as long as there is not rotation of the graphics context involved, the rendered shadow is correct. There's a radar on a related issue raised before by @garrettmoon (and commented on by @alexleutgoeb): http://openradar.appspot.com/8571017.

As a workaround, rendering to UIWindow and then rotating the generated image might be a good work around?

@vpdn
Copy link
Owner

vpdn commented May 27, 2014

I've now also file a radar (rdar://17035663) for the issue. I think the best would be now to go with the route of rendering the UIWindow and rotating the generated image, as stated above, @jwalapr what you think?

Also please note that I had to make some modifications to the API, to make it saner to work with. The API should be pretty stable now as is. The podspec (v0.2.1) is updated to point to the new API.

Jason Prasad added 2 commits May 27, 2014 20:33
@obj-p
Copy link
Contributor Author

obj-p commented May 28, 2014

Just changed it to apply the transforms to the generated images. Let me know what you think.

@vpdn vpdn merged commit 3084cc3 into vpdn:master May 28, 2014
@vpdn
Copy link
Owner

vpdn commented May 28, 2014

@jwalapr Merged, thanks! I've bumped up the podspec version to include your change and updated the README to mention you as the originator of the fix.

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

Successfully merging this pull request may close these issues.

2 participants