加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – 如何使子视图填充其超视图

发布时间:2020-12-16 05:38:16 所属栏目:百科 来源:网络整理
导读:我在这里找不到答案,也没有看到重复的问题. 我的代码很简单给定3个UIView,parent,from和to,从父中删除并添加子视图.添加动画,但只是doodads. 现在,问题是当我这样做,然后被抵消.就好像被推倒了 我甚至添加To.frame = ParentView.frame;以确保它有效.没有 我
我在这里找不到答案,也没有看到重复的问题.

我的代码很简单给定3个UIView,parent,from和to,从父中删除并添加子视图.添加动画,但只是doodads.

现在,问题是当我这样做,然后被抵消.就好像被推倒了

我甚至添加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},460}}

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

我在SimulatedMetric部分中将statusbar设置为none.

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读