1

我将方向设置为 RootViewController 中左侧的横向,但在 viewDidLoad 或 viewWillAppear 中,VC 的视图边界不旋转。在 viewDidAppear 中,它有一个正确的框架。我觉得在 viewDidAppear 中不是一个好地方,我该怎么办?

    @implementation RootViewController


    - (void)viewDidLoad
    {
        [super viewDidLoad];
        CGRect frame = self.view.bounds;
    }

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        CGRect frame = self.view.bounds;

    }

    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        CGRect frame = self.view.bounds;
    }

    #pragma mark - Orientation

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
        return toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft;
    }

    //for iOS 6 or later

    - (BOOL)shouldAutorotate
    {
        return YES;
    }

    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskLandscapeLeft;
    }

    @end        

日志显示:

    viewDidLoad,x = 0.000000, y = 0.000000,w = 300.000000 h = 480.000000
    viewWillAppear:,x = 0.000000, y = 0.000000,w = 300.000000 h = 480.000000
    viewDidAppear:,x = 0.000000, y = 0.000000,w = 480.000000 h = 300.000000
4

2 回答 2

1

您可以在方向更改后设置框架:

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
于 2012-11-30T08:47:03.557 回答
0

我认为它应该在这个函数中

  • (void)viewDidLayoutSubviews { }

苹果的文档说在此处输入图像描述

于 2012-11-30T09:02:16.617 回答