How to detect orientation in costomNavigationbar? - iphone

i need to draw PortraitImage or LandscapeImage when my costomNavigation has been change to portrait or landscape.

You need to override willRotateToInterfaceOrientation:duration: in your UIViewController. This will give you a call every time the app changes its orientation.

You can detect orientation by using the UIDevice Class, as shown here:
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/occ/instp/UIDevice/orientation
You need to use the methods
- (void)beginGeneratingDeviceOrientationNotifications
and
- (void)endGeneratingDeviceOrientationNotifications
That should probably work.

Related

Eliminate Rotation Orientation in Objective-C

Currently, in my app, I need to NOT allow side orientation to occur except for one view that is supposed to show another uiview when the user side-orients. Suppose I have 20 UIViewControllers that are allowed to be accessed from the mainviewcontroller (UINavigationController). Now, also suppose that UIViewController #7, when shown has two views, one that is shown for side orientation and one for portrait orientation.
I don't want you guys to think I want to eliminate Rotation Orientation throughout the app's life but just for 19 of the views, and the last uiviewcontroller have support for it.
If a user does side-orient for that one view, then the user should just see the app as usual with no orientation effects.
I want the user to only use the portrait orientation view and thats it for that one viewcontroller. Maybe if the user rotates the phone 180 degrees, upsidedown, then sure, the app should flip but still be in a portrait view.
ANyone have any ideas? I'm deploying to iOS 6.1 so some methods I have used are deprecated which is what I want to stay away from...
Such as this method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return NO;
}
I have done several test cases:
- (NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (BOOL) shouldAutorotate{
return NO;
}
I've also checked up on stackoverflow related questions and I can't simply find an answer.
I figure this should be one maybe two methods I override but I can't do this..... How do I eliminate side orientation in a UIViewController????
There are questions on SO that cover this topic; there's a wealth of information here, for example.
Or, how about this, or this?
IIRC, from one of the WWDC videos I watched on this subject, the recommended way was to do a modal presentation, but there are various hacks at your disposal if you're so inclined.
Edit:
More data here: iOS6 Preferred Interface Orientation Not Working
And here: In iOS6, trouble forcing ViewController to certain interfaceOrientation when pushed on stack
As I said, I believe presenting the view controller (modally or whatnot) is the way to go if you want to force an orientation, see this explanation.

How do I call shouldAutorotateToInterfaceOrientation method?

i developing an iPad app in which i working with images.The application is worked fine in portrait mode when application launched in portrait mode but it gives me ridiculous problem with frames when app i launched in landscape mode. My all functionality already written in "shouldAutorotateToInterfaceOrientation" this method. If i able call this method then it will remove all problem of frames.How i call shouldAutorotateToInterfaceOrientation method in my application in any function?
You don't call shouldAutorotateToInterfaceOrientation: yourself. UIKit sends this message to your view controller in order to know if the view controller should be rotated or not. Move your layout code from shouldAutorotateToInterfaceOrientation: to willRotateToInterfaceOrientation: and it should work.
Check out the UIViewController Class Reference.
shouldAutorotateToInterfaceOrientation:
Your implementation of this method should simply return YES or NO based on the value in the interfaceOrientation parameter. Do not attempt to get the value of the interfaceOrientation property or check the orientation value reported by the UIDevice class. Your view controller is either capable of supporting a given orientation or it is not.

How to respond to interface orientation changes?

I know the app delegate can say "yo man, I want thais new landscape orientation!" or "no thanks, don't want landscape!" and then the device won't do it.
How to implement this?
The active view controller's shouldAutorotateToInterfaceOrientation: method determines whether the interface will rotate.
For launch, there is a key in your Info.plist file that needs to be set if you want to be able to launch in orientations other than portrait.
I prefer to get the orientation notification by registering UIDeviceDidChangeOrientationNotification. The delegate of UIViewController about orientation always confuses me. I prefer to control the animation effect by myself.

Make UIView Landscape Orientation in UIViewController?

I have added a UIView as subview of my UIViewController, when I am trying change the orientation, it is not working, Please let me know how should i change the Interface orientation of my UIView?
Regards
Sri
try this..
[[UIDevice currentDevice] performSelector:#selector(setOrientation:) withObject:(id)UIInterfaceOrientationLandscapeRight];
Make sure you return YES for -shouldAutorotateToInterfaceOrientation: in your view controller.
Note that setOrientation is a private API according to the documentation of UIDevice (that property is read only). If you use it, your application will be rejected during the App Store review.
Instead forcing an orientation, you should override shouldAutorotateToInterfaceOrientation in all the view controllers of the hierarchy of that view and return YES only for the orientations you want to support.

Single-Stage vs Two-Stage Animation for iPhone Apps?

What are single-state and two-stage animation for rotating an iPhone window?
This is the "error" message I get in the Debugger Console (nothing crashes):
Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.
I was working through the book "Beginning iPhone Development: Exploring the iPhone SDK" by Apress (Dave Mark, Jeff LaMarche) on the Swap Project.
Everything is explained in the UIViewController Class Reference. Especially check out the View Rotation section near the top.
From the reference:
Handling View Rotations
By default, the UIViewController class
displays views in portrait mode only.
To support additional orientations,
you must override the
shouldAutorotateToInterfaceOrientation:
method and return YES for any
orientations your subclass supports.
If the autoresizing properties of your
views are configured correctly, that
may be all you have to do. However,
the UIViewController class provides
additional hooks for you to implement
additional behaviors as needed.
To temporarily turn off features that
are not needed or might otherwise
cause problems during the orientation
change, you can override the
willRotateToInterfaceOrientation:duration:
method and perform the needed actions
there. You can then override the
didRotateFromInterfaceOrientation:
method and use it to reenable those
features once the orientation change
is complete.
If you want to perform custom
animations during an orientation
change, you can do so in one of two
ways. Orientation changes used to
occur in two steps, with notifications
occurring at the beginning, middle,
and end points of the rotation.
However, in iPhone OS 3.0, support was
added for performing orientation
changes in one step. Using a one-step
orientation change tends to be faster
than the older two-step process and is
generally recommended for any new
code.
To add animations for a one-step
orientation change, override the
willAnimateRotationToInterfaceOrientation:duration:
method and perform your animations
there. To use the older two-step
method, override one or both of the
willAnimateFirstHalfOfRotationToInterfaceOrientation:duration:
and
willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:
methods to configure your animations
before each step. You must choose only
one technique and override just the
methods associated with that
technique. If you override either
method associated with the two-step
technique, the view controller uses
that technique by default.
I have found the culprit in my case to be the UIImagePickerController (I also do not override any rotation animation):
[self presentModalViewController:imagePicker animated:YES];
Replacing imagePicker with a generic UIViewController doesn't generate any warnings.
I changed from willAnimateFirstHalfOfRotationToInterfaceOrientation:duration: method to willAnimateRotationToInterfaceOrientation:duration: method and warning gone.
Thanks.
Ed Marty's answer is the correct one. The reason it will happen if you are not overriding any of the rotation animation is probably that you reply "YES" to shouldAutorotate.. for some view. If you do not implement rotation at all, then you should just not override the shouldAutorotate.. method. If you do override that method, then just override the single step rotation method as well and pass it along to the super.
If you're using iOS 4 and you're getting this warning, I found a way to get rid of it. In your info.plist, there is an item called "Supported interface orientations." Select which orientations your application supports and two-stage warnings will go away when bringing up the imagePicker.
#plumiscles answer didn't quite work for me - there was no item called 'Supported Interface Orientations', probably b/c it is an old project. But you can get the same effect by editing the .plist file directly and adding this:
<key>UIInterfaceOrientation</key>
<string>UIInterfaceOrientationPortrait</string>
Need to add UIImagePickerController as a subview to solve this error
[self.view addSubview:picker.view];
[self presentModalViewController:picker animated:NO];
I've had this issue after creating a tabbarcontroller with no view controllers inside (no tabs), this warning disappeared once I attached at least one view controller to it.
I wasn't over riding any of those two-step functions, but I was calling my own function when I received orientationChanged notifications, and I had this line of code in it. Commenting it out got rid of the warning and allowed the auto rotate to work properly. Auto rotate still worked with this line of code until iOS 4.2, then it broke completely. Spent a lot of time looking for why the built in autoRotate stopped working in 4.2. Maybe this will help someone else.
Commented out this line to make it work:
[[UIApplication sharedApplication] setStatusBarOrientation:currentOrientation animated:YES];
I've delete from plist "Supported interface orientations" row and warning disappears.
I just had the same problem. In my case was a silly mistake that I'm putting here just in case anyone else falls into that same issue.
In my tabbed app I remove one of the original ViewControllers and added a new one with Storyboard to create a "Settings" section.
This new VC had to be a table view VC and even I designed, compiled and run it without a problem, when I changed the orientation of the app I kept getting this “Using two-stage rotation animation” error.
My problem was that I forgot to change in the original .h file interface "UIViewController" for "UITableViewController".
Once this was done I changed on the Storyboard identity badge the class from the general value to my SettingsViewController and that was the end of it.
I hope it can help someone else. It took me a while to get to bottom of this.
Cheers,