1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

question about willAnimationRotate and didRotateFrom, iphone

Discussion in 'iPhone/iPad Programming' started by tranvutuan, Feb 11, 2012.

  1. macrumors member

    #1
    What I am having so far is
    Code:
    -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
        
        NSLog(@"willAnimateRotationToInterfaceOrientation");
        if(toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
             NSLog(@"PortraitUpsideDown");
             // Do method A
        }
        else {
            [[self.view subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
            // Do method B
            
        }
    }
    and
    Code:
    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
    {
        NSLog(@"didRotateFromInterfaceOrientation");
        if( fromInterfaceOrientation == UIInterfaceOrientationPortrait || fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
            NSLog(@"OrientationPortrait or PortraitUpsideDown");
            [[self.view subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
            // Do method B
        }
        else {
             NSLog(@"From else");
            [[self.view subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
            // Do method A
            
        }
    }
    My logic is after hitting the RUN from xcode, willAnimateRotationToInterfaceOrientation is going to be called because I set Supported Device Orientation to be UpsideDown from Summary of MyApp.xcodeproj.Moreover, I also think that didRotateFromInterfaceOrientation should not be called because we have just started the app yet. It means there is no previous state at all.
    Unfortunately, this is what I got after doing the debugger
    Code:
    2012-02-11 12:04:08.776 MyApp[7505:10703] willAnimateRotationToInterfaceOrientation :
    2012-02-11 12:04:08.776 MyApp[7505:10703] PortraitUpsideDown
    2012-02-11 12:04:08.778 MyApp[7505:10703] didRotateFromInterfaceOrientation :
    2012-02-11 12:04:08.779 MyApp[7505:10703] OrientationPortrait or PortraitUpsideDown
    I am getting lost now. Does anyone have any ideas about the issue, please help. Thanks.
     
  2. macrumors member

    #2
    Apps always start in the same interface orientation as the springboard. On an iPhone or iPod touch, this is always UIInterfaceOrientationPortrait. Thus, if you have the device positioned upside down, the app starts in portrait and your root view controller receives the orientation change as soon as the window becomes visible.
     
  3. macrumors member

    #3
    Thanks for your answer, it helps me to understand the reason now.
     

Share This Page