It looks like the Resized event is reporting the previous window size when the screen orientation is changed.
Debug output here shows the value from the Resized event, graphic is just a 320x200 sprite, and I'm not transforming either the sprite or the view at any point: https://www.youtube.com/watch?v=cJ2af72hiDo
I've tested this on iOS 11 and 9, and I'm using Xcode 9 on macOS 10.13. Has anybody else got this working successfully?
Example code (Not the one used in above video, but has same outcome for me)
sf::RenderWindow window(sf::VideoMode(),"SFML Doesn't work :(");
sf::RectangleShape shape;
shape.setFillColor(sf::Color::Red);
while(window.isOpen())
{
sf::Event ev;
while(window.pollEvent(ev))
{
if (ev.type == sf::Event::Resized)
{
std::cout << std::to_string(ev.size.width) + "," + std::to_string(ev.size.height) << std::endl;
shape.setSize(sf::Vector2f(ev.size.width,ev.size.height));
}
}
window.clear();
window.draw(shape);
window.display();
}
I've finally got round to debugging this a bit more, and have found there's a couple of things which came together to cause this:
- I haven't been specifying a window style, presuming it was being ignored on iOS, but the autorotate flag is being set based on whether sf::Style::Resize is set. This means specifying sf::Style::Fullscreen (or any style without the Resize bit set) stops the screen from rotating (https://github.com/SFML/SFML/blob/5d7843c58a850b4941d7d9794d6fede2bbc02833/src/SFML/Window/iOS/WindowImplUIKit.mm#L86)
- When the autorotate flag is set, the screen rotates based on the supported orientations defined in the Application bundle properties (Info.plist). If this property doesn't exist, then the OS seems to assume that all orientations are supported, however SFML assumes none are supported (https://github.com/SFML/SFML/blob/master/src/SFML/Window/iOS/SFAppDelegate.mm#L176)
For the first point, I can kind of see the connection now between autorotation and sf::Style::Resize, however I don't find it terribly intuitive. I'd prefer a more explicit way of specifying whether to autorotate or not, does anybody have an opinion on how this could fit into the API?
For the second point, I'd say we should assume the same as the OS, which simply means changing it to return false on the line I linked above. This means the event contains the correct window sizes, however upside-down orientation doesn't look completely correct...
I think for the second point it actually needs to return (1 << orientation) & [rootViewController supportedInterfaceOrientations]
but have SFML's override of supportedInterfaceOrientations removed, because the override just returns that all orientations are supported, whereas the default returns different values for iPhone/iPad, and matches what I'd expect (and fixes the issue) based on documentation here: https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations
I'm still kind of learning this as I go along, so anybody with more experienced input please speak up!