Autorotation & Positioning Problem

Joined
Oct 11, 2011
Messages
46
Reaction score
0
Points
6
Your Mac's Specs
13" MacBook Pro 2.4 GHz 8 GB Ram 250 GB HD, iPhone 4/S 64 GB, iPhone 3GS 16 GB, iPad 16 GB Wi-Fi
On my app i found this problem, when in landscape mode and i select an item which leads to another view, my description doesn't show up.


but when im in portrait view and i select the item, and than i rotate it, THEN for some reason my description shows:


heres the a photo of the view when i use the app in landscape mode only


m3rk8.png





heres the photo of the view, when i use the app in portrait mode and than rotate it to landscape when im at this view. so you guys have some type of idea what im talking about


2lcvdz9.png






heres my coding:


Code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{      
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    
    if ([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    else
    {
        if (UIInterfaceOrientationIsPortrait(interfaceOrientation))
        {
            // Portrait frames
            view_style_descript.frame = CGRectMake(0, 664, 768, 90);
            view_Washing_Intrn.frame=CGRectMake(0, 753, 768, 158);
            //[self RemoveSubView];
            //view_color.frame = CGRectMake(710, 80, view_color.frame.size.width, view_color.frame.size.height);
        }
        else
        {
            // Landscape frames
            view_style_descript.frame = CGRectMake(465, 200, 560, 90);
            view_Washing_Intrn.frame=CGRectMake(465, 290, 560, 250);
           // [self RemoveSubView];
            //view_color.frame = CGRectMake(965, 80, view_color.frame.size.width, view_color.frame.size.height);
        }

        return YES;
    }
}



- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    
    if ([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPad)
    {
        if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation))
        {
            // Portrait frames
            view_style_descript.frame = CGRectMake(0, 664, 768, 90);
            view_Washing_Intrn.frame=CGRectMake(0, 753, 768, 158);
            
            
            if(ShowColor==FALSE)
            {
                view_color.frame = CGRectMake(710, 80, view_color.frame.size.width, view_color.frame.size.height);
            }
            else
            {
                view_color.frame = CGRectMake(665, 80, view_color.frame.size.width, view_color.frame.size.height);
            }
        }
        else
        {
            // Landscape frames
            view_style_descript.frame = CGRectMake(465, 200, 560, 90);
            view_Washing_Intrn.frame=CGRectMake(465, 290, 560, 250);
            if(ShowColor==FALSE)
            {
               view_color.frame = CGRectMake(965, 80, view_color.frame.size.width, view_color.frame.size.height);
            }
            else
            {
                view_color.frame = CGRectMake(925, 80, view_color.frame.size.width, view_color.frame.size.height);
            }
        }

    }
    
}



these do not work, i tried using the If statement on viewDidLoad, but it doesn't know if its in portrait mode or landscape.


Code:
- (void)viewDidLoad
{  
    [super viewDidLoad];
    
    
    if (UIInterfaceOrientationPortrait)
    {
        // Portrait frames
        view_style_descript.frame = CGRectMake(0, 664, 768, 90);
        view_Washing_Intrn.frame=CGRectMake(0, 753, 768, 158);
        //[self RemoveSubView];
        //view_color.frame = CGRectMake(710, 80, view_color.frame.size.width, view_color.frame.size.height);
    }
    else
    {
        // Landscape frames
        view_style_descript.frame = CGRectMake(465, 200, 560, 90);
        view_Washing_Intrn.frame=CGRectMake(465, 290, 560, 250);
        // [self RemoveSubView];
        //view_color.frame = CGRectMake(965, 80, view_color.frame.size.width, view_color.frame.size.height);
    }

}

so basically if i put a "!" infront of UIInterfaceOrientationPortrait it executes the else statement, if not than the if.


anyone have any suggestions or advice???
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
Firstly you should not use the shouldAutorotateToInterfaceOrientation: Method to reposition views or subviews, only use the shouldAutorotateToInterfaceOrientation: Method to return the desired or supported device orientations only, like this.

Code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (UIInterfaceOrientationIsPortrait(interfaceOrientation) || UIInterfaceOrientationIsLandscape(interfaceOrientation));
}

The above example allows for all device orientations, including portrait upside down.

Secondly you should use the viewControllers viewDidLoad: viewWillAppear: or viewDidAppear Methods to check the devices orientation, and do any repositioning code.

Hope this helps.

Regards mark
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top