Objective c 如何使子视图填充其超级视图
无论如何,我在这里找不到答案,也看不到重复的问题 我的代码很简单。给定3个UIView、parent、from和to、remove from from parent和add subview添加动画,但这只是涂鸦 现在,问题是当我这样做的时候,我的大脑就会被抵消。就好像它被推下去了 我甚至添加到.frame=ParentView.frame;确保它能正常工作。没有 我该怎么办Objective c 如何使子视图填充其超级视图,objective-c,xcode,subview,addsubview,superview,Objective C,Xcode,Subview,Addsubview,Superview,无论如何,我在这里找不到答案,也看不到重复的问题 我的代码很简单。给定3个UIView、parent、from和to、remove from from parent和add subview添加动画,但这只是涂鸦 现在,问题是当我这样做的时候,我的大脑就会被抵消。就好像它被推下去了 我甚至添加到.frame=ParentView.frame;确保它能正常工作。没有 我该怎么办 + (void) AnimateSwitchingWithParent: (UIView *) ParentView Fr
+ (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}
但是,如果我删除到.frame=ParentView.frame,则该帧也会被删除
{0,20},{320,460}
我想知道为什么?20点似乎是状态栏的距离。在InterfaceBuilder中,我们可以在哪里设置该框架
我在SimulatedMetric部分将statusbar设置为none。似乎您误解了框架和边界,请将代码修改为
到.frame=ParentView.bounds代码>应该可以
相关:修复子视图和Swift视图中底部的20点差异:
To.frame = NSRect(origin: CGPoint(x: ParentView.bounds.origin.x,
y: ParentView.bounds.origin.y-20),
size: ParentView.bounds.size)
Objective-C约定要求变量以小写字母开头(大写仅用于类/协议名称)。请坚持下去。你(未来?)的同事会为此感谢你。关键是框架
位于superview的superview坐标中<代码>边界
位于视图的坐标中。如果使用的是frame
,并且superview在其父视图中偏移,则无法正常工作。