c# - 是否可以调整 UITabbarcontroller 的子视图的大小?
问题描述
所以我得到了一个这样的故事板布局:
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();
});
解决方案
有可能,但是前提是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);
推荐阅读
- javascript - cs-Cz 语言环境和 JavaScript 新日期构造函数不允许速记日期
- java - 我需要从现有领域数据库中读取数据
- javascript - JSX this.state.STATE.map 不是一个函数
- python - 使用 Numpy 的正态分布
- woocommerce - 将客户条纹支付数据从 Squarespace 迁移到 Woocommerce
- javascript - 如何根据先前的选择标签重置选择中的默认值?
- bash - 为什么 bash 将每个字符都视为一个数字
- .htaccess - 如何将某些文件的访问列入.htaccess中某些子域的白名单
- python - 每日排行榜或价格跟踪数据
- javascript - 如何将 HTMLAudioElement 音频文件上传到节点服务器?