gpt4 book ai didi

ios - 在 IOS 中使用约束将 UIView 中的 subview 居中

转载 作者:行者123 更新时间:2023-11-29 00:13:04 25 4
gpt4 key购买 nike

我在 UIView 内的 UIViewController 中有三个 subview ,如 subview1、subview2、subview3。

我正在对它们使用约束,当单击按钮时我用来在中心显示的约束是这些,

  • 水平放置在容器中,
  • 垂直放置在容器中,
  • 宽度和
  • 高度。

问题:

当我运行应用程序并在它到达正确位置时单击 按钮。但是,当我关闭它并再次尝试打开它时,subview 会更改其位置本身并位于 UIViewcontroller左上角

正如您在屏幕截图中看到的,但每次我单击 UIViewcontroller< 的中心中的按钮时,我都想显示 View /

我很困惑约束是正确的,但为什么当我们再次打开它时它总是改变它的位置。

image

我的代码是,

    - (IBAction)Precord:(id)sender {

_DateView.hidden=NO;
[self.DateView bounceIntoView:self.view direction:DCAnimationDirectionLeft];
}

Storyboard中的内容是这样的, enter image description here

最佳答案

这取决于您关闭 View 的方式。我刚刚尝试了下面的代码,它对我有用

- (IBAction)btn_Tapped:(id)sender {
_smallView.hidden = false;
[_smallView bounceIntoView:self.view direction:DCAnimationDirectionLeft];
}
- (IBAction)hide_Tapped:(id)sender {
_smallView.hidden = true;
}

基本上我只是隐藏 View 。当 btn_Tapped 时,每次 View 都在中心显示弹跳动画。让我知道你过得怎么样!

关于ios - 在 IOS 中使用约束将 UIView 中的 subview 居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45859291/

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