9

无论如何,我在这里找不到答案,也没有看到重复的问题。

我的代码很简单。给定 3 个 UIView,parent,from 和 to,从 parent 中删除并添加 subview。+ 添加动画,但这只是小玩意。

现在,问题是当我这样做时,然后会被抵消。好像被压下去了一样。

我什至添加了 To.frame=ParentView.frame; 以确保它有效。它没有。

我应该怎么做?

+ (void) AnimateSwitchingWithParent: (UIView *) ParentView From: (UIView *) From To: (UIView* ) To
{
    /*[UIView beginAnimations:@"View Flip" context:nil];
    [UIView setAnimationDuration:1.25];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];


    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:ParentView cache:YES];*/
    [From removeFromSuperview];
    [ParentView addSubview:To];

    To.frame=ParentView.frame; //If I don't do this, the subview is still off by around 20 points
    NSLog(@"To.bounds: %@", NSStringFromCGRect(To.bounds));
    NSLog(@"From.bounds.: %@", NSStringFromCGRect(From.bounds));
    NSLog(@"ParentView.bounds: %@", NSStringFromCGRect(ParentView.bounds));


    //JA_DUMP (To.bounds);
    //JA_DUMP (To.bounds);



    /*[UIView commitAnimations];*/

}

我已经想出了解决方案。原来 To 的框架是

To.frames: {{0, 0}, {320, 372}}

但是,如果我删除 To.frame=ParentView.frame 框架也是

{{0, 20}, {320, 460}}

我想知道为什么?20点似乎是状态栏的距离。我们可以在 InterfaceBuilder 中的哪里设置该框架?

我在 SimulatedMetric 部分将状态栏设置为无。

4

2 回答 2

20

似乎你误解了框架和界限,修改你的代码To.frame=ParentView.bounds;应该可以。

相关:为什么在 UIView 中有一个框架矩形和一个边界矩形?

于 2011-06-19T12:18:14.330 回答
0

修复20 pointsSwift 中 subView 和 View 与底部的“”差异:

To.frame = NSRect(origin: CGPoint(x: ParentView.bounds.origin.x, 
                                  y: ParentView.bounds.origin.y-20), 
                    size: ParentView.bounds.size)
于 2015-03-03T10:08:04.310 回答