R. Dewi
R. Dewi

Reputation: 4271

how to autorotate a subview in navigation controller

i have a subview in navigation controller, when the ipad simulator rotate to be portrait or landscape, the main view is autorotate fit into the ipad orientation, but the subview is not. the subview is rotate too, but not fit into the ipad orientation, the subview orientation is always landscape toward the ipad home button.

my question is, how to make the subview autorotate and have orientation like the main view's orientation???

can some body help me, please...

Upvotes: 0

Views: 1775

Answers (1)

R. Dewi
R. Dewi

Reputation: 4271

I have solved this problem.

I use the NSNotification function in the subview viewController class, in the viewWillAppear method, this is my implementation:

[[NSNotificationCenter defaultCenter]
 addObserver:self
 selector:@selector(deviceRotated:)
 name:UIDeviceOrientationDidChangeNotification
 object:[UIDevice currentDevice]];

and then, this is the deviceRotated method :

-(void)deviceRotated:(id)sender{
    UIDeviceOrientation orientation = [[UIDevice currentDevice]orientation];
    if (orientation == UIDeviceOrientationPortrait) {
        CGAffineTransform rotate = CGAffineTransformMakeRotation (0.0);
        CGAffineTransform translate = CGAffineTransformMakeTranslation(0, 30);
        self.alertView.transform = CGAffineTransformConcat(translate, rotate);

    }   
    else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
        CGAffineTransform rotate = CGAffineTransformMakeRotation (M_PI * 180 / 180.0f);
        CGAffineTransform translate = CGAffineTransformMakeTranslation(-63, -100);
        self.alertView.transform = CGAffineTransformConcat(translate, rotate);

    }else if (orientation == UIDeviceOrientationLandscapeLeft) {
        CGAffineTransform rotate = CGAffineTransformMakeRotation (M_PI * 90 / 180.0f);
        CGAffineTransform translate = CGAffineTransformMakeTranslation(60, -180);
        self.alertView.transform = CGAffineTransformConcat(translate, rotate);


    }else if (orientation == UIDeviceOrientationLandscapeRight) {
        CGAffineTransform rotate = CGAffineTransformMakeRotation ( M_PI * 270 / 180.0f);
        CGAffineTransform translate = CGAffineTransformMakeTranslation(-60, -140);
        self.alertView.transform = CGAffineTransformConcat(translate, rotate);

    }   
}

Finally, the problem is solved. And this is the link that help me.

Upvotes: 6

Related Questions