objective-c - 我应该在哪里设置 ViewController 中的 subview 框架

标签 objective-c ios uiviewcontroller

我在 RootViewController 中将方向设置为横向,但在 viewDidLoad 或 viewWillAppear 中,VC 的 View 边界没有旋转。在 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

最佳答案

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

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

关于objective-c - 我应该在哪里设置 ViewController 中的 subview 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13641641/

相关文章:

iOS 本地存储的任何大小限制

ios - 在第二个 View Controller 上加载、保存高分

iphone - 如何设置 iPod 音量而不影响其他音量?

ios - 参数在 SOAP 服务中传递 NULL 值

objective-c - 制作一个按钮向标签添加一个数字

ios - 为 View Controller Root View 设置外观代理

ios - UIViewController 的默认自定义过渡

iphone - 更改 Nib 时不会调用 Dealloc

ios - 无法完成付款队列中未完成的交易

ios - 具有警报级别的 UIWindow 位于状态栏级别之上