Application orientation on iOS device

360 views
Skip to first unread message

Patorikku

unread,
Jul 25, 2012, 4:25:00 AM7/25/12
to kivy-...@googlegroups.com
Hi,

By default the kivy-ios/tools/create-xcode-project.sh generates the Xcode project file for iPad in Landscape mode. I want to make the app Portrait only, however changing the Supported Device Orientations inside project settings doesn't seem to work.

From the docs I know I can do this:

from kivy.config import Config

Config.set('graphics', 'rotation', '90')

And get the look right, but doesn't feel right - if there is TextInput widget and when I tap on it, the onscreen keyboard will come out on the left hand side of the screen, rather than from button, because the iOS thinks the app is always in landscape mode.

Then I tried this but no success:

from kivy.config import Config
Config.set('graphics', 'fullscreen', '1')
Config.set('graphics', 'width', '768')
Config.set('graphics', 'height', '1024')
Config.set('graphics', 'top', '0')
Config.set('graphics', 'left', '768')

How do I set it to Portrait mode only when the app is launched?

Cheers,
Pat

Patorikku

unread,
Jul 27, 2012, 8:56:54 AM7/27/12
to kivy-...@googlegroups.com
Ok found the issue and solution myself :)

When Kivy starts up with SDL for the Window construction, it has Landscape mode hardcoded so it doesn't support Portrait at all.

I have made the following changes to make the app runs in all orientations and starts up in Portrait by default, then run tools/build-kivy.sh again.

diff --git a/kivy/core/window/sdl.pyx b/kivy/core/window/sdl.pyx
index b64ef51..25e94be 100644
--- a/kivy/core/window/sdl.pyx
+++ b/kivy/core/window/sdl.pyx
@@ -156,9 +156,9 @@ def setup_window(width, height, use_fake, use_fullscreen):
 
     if SDL_Init(SDL_INIT_VIDEO) < 0:
         die()
-
-    # Set default orientation (force landscape for now)
-    SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight")
+    
+    # Support all orientations
+    SDL_SetHint(SDL_HINT_ORIENTATIONS, "Portrait PortraitUpsideDown LandscapeLeft LandscapeRight")
 
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1)
     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16)
@@ -182,7 +182,8 @@ def setup_window(width, height, use_fake, use_fullscreen):
     SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
     '''
 
-    win = SDL_CreateWindow(NULL, 0, 0, width, height, win_flags)
+    # Create the window in Portrait mode first
+    win = SDL_CreateWindow(NULL, 0, 0, height, width, win_flags)
     if not win:
         die()

Hope it helps.

hugo

unread,
Sep 7, 2012, 8:28:41 AM9/7/12
to kivy-...@googlegroups.com
Works for me too. Do I make a pull request?

blaine

unread,
Sep 25, 2012, 4:20:51 PM9/25/12
to kivy-...@googlegroups.com
Awesome. What's the best way to do this other than me making this change locally myself?

blaine

unread,
Sep 25, 2012, 4:24:27 PM9/25/12
to kivy-...@googlegroups.com
hmm. So I don't have a/kivy/core/window/sdl.pyx on either my mac or my local dev machine. Any tips? Do I have the wrong version? Using the latest kivy from what I can tell.

On Wednesday, July 25, 2012 4:25:00 AM UTC-4, Patorikku wrote:

blaine

unread,
Sep 25, 2012, 4:27:44 PM9/25/12
to kivy-...@googlegroups.com
I see. I do have it inside kivy-ios/tmp though... not sure where it is generated from. Still looking.


On Wednesday, July 25, 2012 4:25:00 AM UTC-4, Patorikku wrote:
Reply all
Reply to author
Forward
0 new messages