gpt4 book ai didi

objective-c - 如何让一个 subview 填充它的父 View

转载 作者:太空狗 更新时间:2023-10-30 03:27:56 25 4
gpt4 key购买 nike

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

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

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

我什至添加 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 部分将状态栏设置为无。

最佳答案

看来你误解了框架和边界,将你的代码修改为 To.frame=ParentView.bounds; 应该没问题。

相关:Why is there an frame rectangle and an bounds rectangle in an UIView?

关于objective-c - 如何让一个 subview 填充它的父 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6402271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com