Autorotation & Positioning Problem

Discussion in 'iOS Programming' started by loon3y, Oct 5, 2012.

  1. loon3y, Oct 5, 2012
    Last edited: Oct 5, 2012

    loon3y macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #1
    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


    [​IMG]




    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


    [​IMG]





    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???




    resolved: i put it in the viewWillAppear like i have below



    [​IMG]
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    UIInterfaceOrientationPortrait is a constant. Being constant, it never changes (by definition; it's constant). So the if condition always has the same result.

    You should review how orientation-changes are actually detected. The relevant method starts with willRotate. Look for the heading "Orientation Changes ...":
    http://developer.apple.com/library/...ges/RespondingtoDeviceOrientationChanges.html
     

Share This Page