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

Added rotation support by placing the messages in the rootViewController... #29

Merged
merged 2 commits into from
Mar 28, 2014

Conversation

DanielKrofchick
Copy link
Contributor

... of their own window. Added rotation notification to resize messages on rotation

These changes add rotation support. For notifications to rotate properly (without resorting to complicated transforms) they need to be a subview of a window's rootViewController. However adding it to the sharedApplication's keyWindow rootViewController causes problems with notifications appearing behind modal controllers that are presented. The best solution is to create another window on top, and add the notifications to it's rootViewController. The last trick is to handle touches for the message views, but pass all other touches to the window below.

This has been tested on iOS 6.1 and 7.1. And works with all rotations on the iPad. I haven't tested rotations on the iPhone, but I don't see why it wouldn't work there as well.

I left the keyWindow naming, although it does now return a view.

…ler of their own window. Added rotation notification to resize messages on rotation
@terryworona
Copy link
Owner

Excited for this fix Daniel! Minimal amount of code change is always nice

I cloned your fork and ran the demo app and can't seem to present any of the messages. showMessage is fired, etc but nothing appears. Can you confirm?

…tes _messageWindow loading below the sharedApplication keyWindow.
@DanielKrofchick
Copy link
Contributor Author

Apologies Terry, I had not tried the changes in the demo app.

I've pushed a fix to master. Here's the commit for reference DanielKrofchick@dc7a5a2.

It appears that the messageWindow was loading behind the keyWindow, obscuring the messages. I'm assuming the messageWindow is loading first, but that is a bit odd. The solution was to lazy load the messageWindow on first access to keyWindow. I'm not aware how to enforce an order for windows, which I think would be preferable.

@terryworona
Copy link
Owner

Ah, I was trying to figure out how the message was able to orient itself properly if the messageBarOffset was hardcoded to 0.0; then I realized it was re-positioned inside the root view. Clever.

I like this implementation. Very clean.

One q: why is the TWTouchForwardingWindow never added a subview? How can it absorb touches and pass them through? How can the root controller's view even show anything? Confused on the magic behind this.

terryworona added a commit that referenced this pull request Mar 28, 2014
Added rotation support by placing the messages in the rootViewController...
@terryworona terryworona merged commit 2f6c3c5 into terryworona:master Mar 28, 2014
terryworona added a commit that referenced this pull request Mar 28, 2014
terryworona added a commit that referenced this pull request Mar 28, 2014
terryworona added a commit that referenced this pull request Mar 28, 2014
@DanielKrofchick
Copy link
Contributor Author

Yeah it is a bit odd, but windows are not added to screens. By default they are associated with the main screen, and all you have to do is set hidden = NO.

The touchForwardingWindow returns nil when it's rootViewController's view is hit (it's subview's were missed), and this passes touches on to the next window. If a subview is hit, a TWMessageView, we return it, and it receives the touch.

@terryworona
Copy link
Owner

Guess I learned something new today. Good stuff @DanielKrofchick, thanks for the contribution. I pulled it in this AM; works great!

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