为了账号安全,请及时绑定邮箱和手机立即绑定

是否可以调整 UITabbarcontroller 的子视图大小?

是否可以调整 UITabbarcontroller 的子视图大小?

C#
aluckdog 2023-07-09 16:38:01
所以我得到了这样的故事板布局:UITabbarcontroller -> child1 -> child2我能够在 child2 的 viewdidload 方法中的 UITabBar 上方动态添加状态栏,如下所示    StatusBar.BackgroundColor = Appearance.ErrorColor.BackgroundColor;    var window = UIApplication.SharedApplication.Delegate.GetWindow();    window.AddSubview(StatusBar);现在的问题是,当我说状态栏存在时,我希望任何孩子的内容都向上移动我尝试了很多排列和方法,包括增加状态栏的大小和减小子视图的大小,但都无济于事。对此提供帮助将不胜感激!    UIView.Animate(0.2, () => {        var frame = this.View.Frame;        this.View.Frame = new CoreGraphics.CGRect(frame.X, frame.Y, frame.Width, frame.Height - 40);        this.View.InvalidateIntrinsicContentSize();        this.View.LayoutIfNeeded();        this.View.SetNeedsLayout();    });
查看完整描述

1 回答

?
慕森卡

TA贡献1806条经验 获得超8个赞

有可能,但是前提是View的Y坐标正好是40,当你隐藏状态栏的时候, Y坐标就变成0了,整个View就会上移。


一般来说,Tabview 子视图的X和Y(0,0)坐标从 开始,而不是从 开始(0,40),因此下面的代码可能不起作用。


UIView.Animate(0.2, () => {

    var frame = this.View.Frame;

    this.View.Frame = new CoreGraphics.CGRect(frame.X, frame.Y, frame.Width, frame.Height - 40);


    this.View.InvalidateIntrinsicContentSize();

    this.View.LayoutIfNeeded();

    this.View.SetNeedsLayout();


});

不过代码是没有问题的,你只需确保子视图的大小从(0,40)开始,就可以看到效果了。


=======================================更新============ =====================


如果您想要转换视图,请按如下方式编码:


UIView.Animate(2, () =>

{

    var frame = this.View.Frame;

    this.View.Transform = new CoreGraphics.CGAffineTransform((System.nfloat)0.8, 0, 0, (System.nfloat)0.8, 0, 0);

    //change contained parameter can modify the level of transform , and even can back to normal status

    this.View.InvalidateIntrinsicContentSize();

    this.View.LayoutIfNeeded();

    this.View.SetNeedsLayout();

});

回到正常状态,替换为:


this.View.Transform = new CoreGraphics.CGAffineTransform(1, 0, 0, 1, 0, 0);


查看完整回答
反对 回复 2023-07-09
  • 1 回答
  • 0 关注
  • 66 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信