0

我有一个视图控制器,它实例化一个子视图控制器,我将它的框架原点 x 从父视图的 viewdidload 设置为 50 并且工作正常,但是当子视图控制器 viewdidload 触发时,我想获取子视图的框架以参考父视图查看控制器的视图,但得到 0。我想是参考子视图控制器而不是父视图控制器获取框架,这是我想要得到的。

本质上,我正在尝试实现平移手势以在父级周围移动子级,这就是为什么我需要它的框架在父级的几何图形中。可能吗?

最终结果是 topview 控制器后面的表格视图,它是类似于 facebook 应用程序中的表格视图。

- (void)viewDidLoad
{
    [super viewDidLoad];
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboardAlpha" bundle:nil];
    self.topViewController = [storyboard instantiateViewControllerWithIdentifier:@"Prime"];

    _layerPosition1 = _topViewController.view.frame.origin.x;
}
- (void)setTopViewController:(UIViewController *)topViewController
{
    CGRect topViewFrame = _topViewController ? _topViewController.view.frame : self.view.bounds;
    topViewFrame.origin.x += 50;
    [_topViewController.view removeFromSuperview];
    [_topViewController willMoveToParentViewController:nil];
    [_topViewController removeFromParentViewController];

    _topViewController = topViewController;

    [self addChildViewController:self.topViewController];
    [self.topViewController didMoveToParentViewController:self];

    [_topViewController.view setAutoresizingMask:self.autoResizeToFillScreen];
    [_topViewController.view setFrame:topViewFrame];
    _topViewController.view.layer.shadowOffset = CGSizeZero;
    _topViewController.view.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.view.layer.bounds].CGPath;

    [self.view addSubview:_topViewController.view];
}

- (NSUInteger)autoResizeToFillScreen
{
    return (UIViewAutoresizingFlexibleWidth |
            UIViewAutoresizingFlexibleHeight |
            UIViewAutoresizingFlexibleTopMargin |
            UIViewAutoresizingFlexibleBottomMargin |
            UIViewAutoresizingFlexibleLeftMargin |
            UIViewAutoresizingFlexibleRightMargin);
}

孩子

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    SoulPrimeOmegaViewController *parent = (SoulPrimeOmegaViewController *)self.parentViewController;
    _layerPosition2 = parent.topViewController.view.frame.origin.x;
}
4

0 回答 0