开发者

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 f开发者_如何转开发it 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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜