使用shouldAutorotateToInterfaceOrientation加载mainView

时间:2010-12-17 20:39:15

标签: iphone sdk

我正在尝试使用shouldAutorotateToInterfaceOrientation方法加载视图,但我遇到了问题。当设备作为横向运行时,我想显示主视图本身,当设备是纵向时,加载自定义UIView。

这是我的代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations

        if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft)|| (interfaceOrientation == UIInterfaceOrientationLandscapeRight))

            //doesn't show main view !!
            self.view;


        else if ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))

            //works fine ! 
            self.view = portraitView;


      return YES;

}

2 个答案:

答案 0 :(得分:0)

我想通了!!!!只需在方法

上使用模态调用视图
- (void) mainView {
    screenTestViewController *mv = [[screenTestViewController alloc]initWithNibName:@"screenTestViewController" bundle:nil];
    [self presentModalViewController:mv animated:NO];

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    // Return YES for supported orientations 

    if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft)|| (interfaceOrientation == UIInterfaceOrientationLandscapeRight))

        [self mainView];


.
.
.

答案 1 :(得分:0)

您应该将自定义UIView推送到:willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration