How to implement rotation in ios 6? - iphone

Below is the code i used for ios5.How do i implement it for ios6?it is not working for me
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation==UIInterfaceOrientationPortrait)
{
rotate=YES;
[self RotatingPotrait];
}
if (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
{
rotate=YES;
[self RotatingPotrait];
}
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
rotate=NO;
[self rotatingLandscape];
}
if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
rotate=NO;
[self rotatingLandscape];
}
return YES;
}
Any help would be appreciated

Why you are not using -willRotateToInterfaceOrientation:duration: ?
From your example it looks like you should move your code from
-shouldAutorotateToInterfaceOrientation:
to
-willRotateToInterfaceOrientation:duration:
BTW. I think, it will good idea to you to take a look to documentation
UIViewController Class Reference and go to section Responding to View Rotation Events, you will find even more handy methods.

Related

Orientation Issues in ios 6.0

I have already completed my app in portrait orientation for iPhone and iPad, Now i need this same for the landscape orientation , I was used only xib's for both iPhone & iPad .and some UI are created in programatically. Just now i was Use this code:
-(NSUInteger)supportedInterfaceOrientations
{
// return your mask here e.g.:
if(UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]))
return UIInterfaceOrientationMaskPortrait;
else
return UIInterfaceOrientationMaskLandscape;
}
but it does not work properly, so can anyone help me......?
Change this code to the following:
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
}
And add the following:
- (BOOL) shouldAutorotate
{
return YES;
}
Finally i done that , now am using this code;
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
// NSLog(#"Landscape left");
} else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(#"Landscape right");
} else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
// NSLog(#"Portrait");
} else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
// NSLog(#"Upside down");
}
}
It was working good for all orientation , Thanq all.

Orientatin issue in ios 6.0 and later

I am developing one application, in which there are number of UIViews inside one UIViewController. Now the issues is that it is having all the UIViews in the Landscape mode, here only one UIView is in portrait. I am not able to get this particular output using shouldAutorotate method.
Can anybody suggest me specific way to short out this issue.
#pratik-bhiyani Thanks...
But I have already done this kind of code to get the specific code when I need to rotate my view
- (IBAction)btnClickToRedeem:(id)sender
{
isPortraitRqurd = TRUE;
[self shouldAutorotate];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if(isPortraitRqurd)
return (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
else
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
if(isPortraitRqurd)
return UIInterfaceOrientationMaskPortrait;
else
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if(isPortraitRqurd)
{
return UIInterfaceOrientationPortrait;
isPortraitRqurd = FALSE;
}
else
return UIInterfaceOrientationLandscapeRight;
}

How to get default LandscapeLeft Orientation in iOS5?

Sorry if this question is duplicate, but I can't find the same solution.
In iOS6, if I want to set default orientation for one UIViewController, I just use:
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeLeft;
}
But how to do same in iOS5, I test both:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);//not default
}
and
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return (toInterfaceOrientation == UIInterfaceOrientationMaskLandscapeLeft);// = return NO;
}
But the default orientation always Portrait.Any suggestion?
call the below method where you want to check the status of orientation.happy coding :-)
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self CheckForViewForOrientation:toInterfaceOrientation];
}
- (void) CheckForViewForOrientation:(UIInterfaceOrientation)orientation
{
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
//Ur lable portrait view
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
//Ur lable for landscape view
}
}
If you want to achieve this for whole application, change supported orientation UISupportedInterfaceOrientations in app.plist file
- (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation==UIInterfaceOrientationPortrait) {
// do some
}
return YES;
}
Include both the methods to support both 5 and 6
You need to provide
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
for that single View controller.

Supporting orientations IOS

Hello i want to support portrait, home button up and down in my application how can i do that?
i go to my project settings check those two
and i add the code below
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
I also tried
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
but none seems to work
any help
Try this
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
if((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)){
return YES;
}
return NO;
}
If it still doesn't work, you can try this (just for the sake of testing)
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return YES;
}
if this doesn't work, either you are not messing with the right view controller, or the parent/root view controller has rotation disabled (returning NO in shouldAutoRotate method of the rootVC)

iPad Rotation, Any Way To Load Custom View Based On Orientation?

Im writing an app that I would like to display different views based on orientation. For example, if the device is portrait load pView, if landscape load lView. Below is the code ive currently tried.
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
self.view = portrait;
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
self.view = portrait;
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
self.view = portrait;
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
self.view = landscape;
}
}
With this I have created 2 views in IB and connected the outlets to the right view. Ive also tried this:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
self.view = portrait;
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
self.view = portrait;
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
lView *abo = [[lView alloc] initWithNibName:#"lView" bundle:nil];
[self.navigationController pushViewController:abo animated:NO];
[abo release];
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
lView *abo = [[lView alloc] initWithNibName:#"lView" bundle:nil];
[self.navigationController pushViewController:abo animated:NO];
[abo release];
}
}
The code directly above worked for ipod but not ipad. Any ideas?
I found the following 2 (Apple) sample projects useful:
http://developer.apple.com/library/ios/#samplecode/AlternateViews/Introduction/Intro.html
http://developer.apple.com/library/ios/#samplecode/WhichWayIsUp/Introduction/Intro.html
Also, remember from a device perspective there is also face-up and face-down orientations; this caught me out.
I have to ask the obvious question:
Do you have the screen orientation lock switch turned on for your iPad?
Depending on what you are trying to do, you can set up your interface in IB to handle rotations automatically. You can resize components, move pics and labels around, stuff like that. That may do what you want to do...