使用父级坐标获取子视图控制器的框架

时间:2013-03-28 03:46:24

标签: ios uiview uiviewcontroller uitableview

我有一个视图控制器,它实例化一个子视图控制器,我从父视图的viewdidload设置它的帧起始x到50并且工作正常,但是当子视图控制器viewdidload触发器时我希望在参考中获取子视图的框架到父视图控制器的视图,但得到0.我想是在引用子视图控制器而不是我想要的父对象框架中获取框架。

基本上我正在尝试实现一个平移手势来将孩子移动到父母身边,这就是为什么我需要父母几何体中的框架。有可能吗?

最终结果是顶视图控制器后面的表格视图,就像在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;
}

0 个答案:

没有答案