Orientation Issues in ios 6.0 - iphone

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.

Related

Orientation issues in Ios 7?

Hi I am working on iphone app (not for ipad) which contains orientation in both protrait and landscape. My problem is sometimes orientation is not done. If i turn device to landscape mode, it is stuck in that mode only, not turn to protrait mode and vice versa.
I dont know the problem. i activated all device orientation modes in deployment info section.
Can anyone tell me the solution for this.
Thanks in advance,
Mahesh.
-(void)viewWillAppear:(BOOL)animated
{
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if(interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown)
{
// Write your orientation code here.
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft||interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
// Write your orientation code here.
}
}
// For ios5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown)
{
// Write orientation code here for ios5
}
else if (interfaceOrientation ==UIInterfaceOrientationLandscapeLeft||interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
// Write orientation code here for ios5
}
return UIInterfaceOrientationMaskAll;
}
// Write code for ios6 and above
-(BOOL)shouldAutorotate
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
return YES;
}
else
return NO;
}
-(void)viewWillLayoutSubviews
{
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if(interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation ==UIInterfaceOrientationPortraitUpsideDown)
{
// Write orientation code here for ios5
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft||interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
// Write orientation code here for ios5
}
}

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;
}

Autorotation for iphone4 & iphone5

Im developing app for both iphone4 & 5. when i use shouldAutoRotation it support only for iphone4. When i use willAnimateRotationToInterfaceOrientation it supports for only iphone5. Im using both method for iphone4 &5, it working. Im going to publish my app to appStore. I got some warnings, but will work perfectly. Is apple reject app for getting warnings.
code:
- (BOOL)shouldAutorotate
{
//returns true if want to allow orientation change
return TRUE;
}
- (NSUInteger)supportedInterfaceOrientations
{
//decide number of origination tob supported by Viewcontroller.
return UIInterfaceOrientationMaskAll;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
//from here you Should try to Preferred orientation for ViewController
return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight | UIInterfaceOrientationPortrait;
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight){
//My code here
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight){
//My code here
}
return YES;
}
you may have missed to close with "}" this method
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight){
//My code here
}
return YES;
}
// add:
return YES;
}
and the same for willAnimateRotationToInterfaceOrientation method...

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.

Issue on UIOrientation in ipad

I'm developing the app for all the orientations in Ipad....But during the development I did only for landscape mode..But nw I want to change to all the possible orientations... Here I got some problem....
Here is the code...
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
//return YES;
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || UIInterfaceOrientationPortrait);
}
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustViewsForOrientation:toInterfaceOrientation];
}
- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
\\Here I did my stuff..
}
else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
\\Here I did my stuff..
}
}
The problem is,When the simulator is launched and if itz in the landscape mode,I got the proper size of the views,but if the simulator is in potrait mode I can't get what I want... If I change the orientations of simulator I get the correct size of the views...
This was the same problem that was facing.
And i solved it by doing this:
First change this function:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
and then in the viewDidLoad function you can check whether the device is in landscape or in Portrait.
-(void)viewDidLoad
{
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
//landscape view code
}
else
{
//portrait view code
}
}
hope this will help