Can you tell which image the iPad has displayed at app launch? (or, I'd like to know the orientation if possible) - iphone

There are a number of similar questions on this site about discovering the orientation of the device in applicationDidFinishLaunchingWithOptions being problematic, but I've yet to find a working solution. The problem I have is that I am adding a full screen image (identical to the currently chosen Default-XXX.png being displayed by the OS to my main window. I do this in order to have an animation happen from the 'splash screen' to my first view controller's view.
Works great, except the device keeps telling me that it is portrait mode - meaning I can't match the image being displayed consistently, since I have different graphics for each orientation)
My understanding is that all apps default to portrait orientation until a rotation occurs inside the app (usually when presenting a viewController) but I'm not 100% convinced.

You should be able to solve this using a view controller. When the application has finished launching, present a view controller in the window. Override the shouldAutorotate… query so that the controller autorotates to portrait/landscape and when you receive one of the rotation callbacks, update the image in the view accordingly. The controller will start up in portrait, but if the device is in some other orientation, the rotation callback will immediately follow and you will get the correct image.
P.S. You might find the Orientation Zoo project helpful when debugging this.

Related

iPhone rotation and full-screen video

I've encountered a strange issue, which I need help resolving. My app is always run in portrait mode - I explicitly want it to be that way. In one place in the app I have a UIWebView, which works just fine, as expected. This web view is not shown all the time but is dynamically added to the main view and removed based on user actions (i.e. it's only visible when I need it to).
Now, sometimes in this view I may have a youtube video. The WebView simply contains the <iframe> for the youtube embed. When a user clicks on the video preview frame in the webview, a full-screen video viewer is launched to play the video - which is just fine.
However if during the playback the user rotates the phone, the full-screen video player is rotated and the video is played in landscape mode. Now the video is stopped and the user presses "Done" button without rotating the phone back to portrait mode, the video player is closed and the user returns to my app - however now my layout is also rotated! Not just the video view, but the entire layout - with toolbar, navigation controller, etc.
I don't want any rotation! I just want everything in my app to remain in portrait mode! Moreover, now even if the phone is rotated back to portrait, the app stays in landscape mode.
Note that I only tested this in a simulator so far, as I currently don't have a physical phone to test. I created a simple (bad quality!) video (just filmed the simulator on my screen with an old phone camera) to demonstrate the issue - the video is here: http://shchuka.com/hosting/rotation_problem.mp4
Any ideas what I can do about it?
Add this in, or change it:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (UIInterfaceOrientation == UIInterfaceOrientationPortrait);
}
That will prevent all rotation and the app will only work in portrait mode. You can place the return statement within IF statements to allow rotation under certain circumstances.
I sometimes add views to the appDelegate window when I want them to be above everything else, and an annoying side-effect has been that I have to explicitly call my own rotation code as there is no VC as such to deal with it. On the plus side, it might mean that it could be ideal for your needs -
[[[[UIApplication sharedApplication] delegate] window] addSubview:myWebView];
...depending on your app's orientation, etc, before you load the view in the first place, you might need to rotate the webView before displaying it.

How can I manually rotate the keyboard (With animation)?

I have a controller that manages a UITextView. Normally, in an app that supports multiple interface orientations, I would simply override -shouldAutorotateToInterfaceOrientation:, set the appropriate auto-resizing masks, and go along my merry way. While going along my merry way, if I were to begin editing this UITextField in, say, portrait mode, then rotate the device to a landscape orientation, the keyboard would animate nicely to landscape mode along with the rest of the view. This is what I want.
Now, in this particular app, I have a root view that must only ever be in portrait mode. This is a camera preview view. I also have an overlay-view for the camera-view that I would like to have support all interface orientations. This is where the UITextView is located.
So, as a result of the fixed-orientation root view, I cannot use built in rotation: I have to do this manually. This isn't a problem, I can register for the UIDeviceOrientationDidChangeNotification and manually animate the appropriate rotation and frame adjustment for the overlay view.
That's good enough to get the view positioned correctly, but the keyboard would still only ever show in portrait orientation. Again, I can correct this with UIApplication's -setStatusBarOrientation: every time I get a notification that the device has rotated.
But that's where the problem arises. I would hope that the combination of:
Register for rotation notifications
Manually rotate view
Set status bar orientation (with animation)
would be enough to exactly replicate the automatic rotation behavior. But it falls short in one important way: If the keyboard were to be shown in one orientation, then rotated to another, the keyboard would remain defiantly in the original position, as if -setStatusBarOrientation: were never called. As far as I know, the only thing that affects the keyboard's presentation is the application's status bar orientation, and there is only the one method for setting it. So am I out of luck? Is it really impossible to make the keyboard rotate with a view manually like it does with auto-rotation?
Addendum
In an effort to avoid covering old ground, I've tried the following solutions hacks:
Upon orientation change, resign and immediately become first responder again. This does make the keyboard move to the appropriate orientation, but it does so without animation, and occasionally does really bad things like show a landscape-sized keyboard in portrait and vice-versa.
Upon orientation change just resign first responder. This also has the odd behavior of instantly moving (but not resizing) the keyboard to the new orientation, then dismissing it with animation. It's very ugly and jarring.
One of our apps does this (because we didn't say "no!" loudly enough when presented with the original design) using crazy "orientation stack" code. I remember fixing this problem by disabling orientation when the keyboard is up (ickyyyy).
Instead, consider supporting rotation by "counter-rotating" the camera preview view instead of forcing the VC to portrait-only. If this looks a bit odd, you can do the "nasty hack" version: Add the camera preview view as a subview of the window, under your VC's view, and give your VC's view a transparent background.
Maybe late to the party. I stumbled upon the same problem. Trying to fix it in iOS 6.
Apparently Apple didn't recognize this problem in the meanwhile, otherwise they would've fixed it by now: have the -setStatusBarOrientation: method include other interface elements besides only the status bar as well, or have alternative methods to set the orientation of the keyboard and other elements. A pity they didn't
Disabling orientation rotation when the keyboard is up, is no solution for me, but I found another simple solution hack:
return NO in -(BOOL)shouldAutorotate
return UIInterfaceOrientationMaskAll in -(NSUInteger)supportedInterfaceOrientations
listen for device rotation notifications
Then when you receive such notification:
hide the status bar
when the keyboard is up, dismiss the keyboard ([myTextField resignFirstResponder])
perform manual rotation animation
set the orientation of the statusbar ([sharedApplication setStatusBarOrientation:newOrientation animated:NO])
show the status bar
if the keyboard was visible before, present it again ([myTextField becomeFirstResponder])
The effect is that the status bar and the keyboard gently slide out before the manual rotation animation and gracefully slide back in, when the animation is done.
BTW, I also found this interesting article by Corey Floyd: http://coreyfloyd.tumblr.com/post/8212203583/2-ways-to-rotate
Although his second method: Tricking UIKit, only caused more confusion with me.

iPhone Game Landscape Orientation Issue

I am trying to make a simple iPhone game and I need the game to be in landscape mode. I can get the initial view to be landscape, but if remove the initial view and replace it with a new view (going from Main Menu to Game Screen) the new view is now in portrait mode. Also, if I switchback to the first view (removing the game screen and then creating the new menu view) the view is still in portrait mode. I have the Info.plist file set up correctly to initialize with landscape right and I have the GameViewController.m file set up with the following code:
-(BOOL) shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
I have read many postings about people having troubles with setting up the landscape orientation, but they always seem to be about the initial load of the app (only displaying one view). I can't seem to find any solutions for this problem. Can someone help me?
You have stumbled on to
one of the most famous bugs on the platform!
Congratulations for spotting it! Here:
iPhone app in landscape mode, 2008 systems
be sure to read the paragraph that begins: "An important reminder of the ADDITIONAL well-known problem at hand here......." !!
It gives you the solution, which is used in all apps.
Make sure that all the view controllers that are visible on screen support the landscape orientation. I would recommend, in your shouldAutorotateToInterfaceOrientation, to return UIInterfaceOrientationIsIsLandscape(interfaceOrientation); instead of your code. This will ensure that both landscape orientation will work. Can you share a bit more how you are switching from the main menu to the game screen?

Iphone sdk custom uiview orientation issue

I am using custom based uiview controller with uitabbar contains uitableview. I am using image for cell background. I want to do orientation from portrait to landscape but the issue is it is not changing on orientation. I just want to know is there are any special thing for custom uiviewcontroller for orientation?
Thanks in advance
Regards,
sathish
If nothing happens when you rotate the device, you either have the system-wide rotation lock enabled (you checked that, right?), or your view controller isn't returning YES to the alternate orientation in its shouldAutorotateToInterfaceOrientation:, or you're doing something odd with your views that means your view controller isn't getting set as the “frontmost” one and thus isn't getting asked about orientation changes. It'll be easier to narrow that down if you post the code you're using to set up the controller and its view.

iPhone autorotation only on specific screens in under a navigation controller

This is just an example of the basic problem I'm having, so don't worry if this situation sounds a bit pointless ;)
Let's say I have an app that's mainly a UINavigationController just two levels deep. The top level is a table with a list of image filenames, and the second level has just a UIImageView showing the image for the filename you tapped.
For an app such as this, does anyone know a good way to allow the table at the top level to autorotate while keeping the second level of images fixed in portrait mode?
So far I've been able to almost get there... but when I tap a filename while in landscape mode, the image slides into view in the wrong orientation even if the second level view controller's shouldAutorotateToInterfaceOrientation returns yes for only portrait modes.
There was no good way to do this in iPhone OS 2.x, but in 3.0, they've dramatically improved it.
In 2.x, the shouldAutorotateToInterfaceOrientation: delegate method was only obeyed for changes to the orientation, so you'd get the behavior you describe: if it was rotated in another view controller, it would stay rotated through pushes and pops even if the new view controller didn't support rotation to that orientation.
In 3.0, UINavigationController polls shouldAutorotateToInterfaceOrientation: on each push or pop and obeys what it returns the way you'd expect, e.g.: if you're currently rotated in Landscape Left orientation, and you push an instance of a view controller that only supports Portrait orientation via shouldAutorotateToInterfaceOrientation:, it automatically and instantly flips the logical orientation and slides in the new view the correct way in Portrait orientation.
Note that this will only work on applications linked against (and therefore requiring) 3.0. For applications linked against 2.x, it will emulate the old behavior.
The problem is that if you use auto rotation the entire UI (including the UIWindow instance I believe) is rotated.
Anything pushed onto the navigation controller at this point will be done in landscape.
So when you push the imageview, that is exactly what you get.
To get this to work, you have to either:
Handle the rotation of the root view
manually (using a transform)
Unrotate the image view by -PI/2
using a transform.
Either way you have to perform the transforms manually to get this to work.
As a side note, this may be bad UI design. As a user, I would expect as I drill down for images to appear rightside up. But this is without knowing the exact context of your app.