gpt4 book ai didi

ios - 将 UIView 从一个选项卡移动到另一个选项卡

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:58:47 24 4
gpt4 key购买 nike

我正在制作这种类型的屏幕。 Tabs
我使用了 3 个 UIButton 并以编程方式为它们设置了边框。小红线是一个 UIView。我已经为 UIView Equal Widths 作为 Trending Button 提供了约束。现在我的问题是,当用户点击下一个按钮时,这个 UIView 应该移动到下一个按钮。

View Controller 是 600x600 并且下一个按钮位于200x0 因此,如果我将 UIView 的值更改为 200,它将被硬编码,并且它会根据屏幕大小而改变。我希望它是完美的,不知道还有什么其他方法。

更新:
我正在使用 AutoLayout 所以为此,我使用了 [self.buttonBottomView setTranslatesAutoresizingMaskIntoConstraints:YES]; 并且当我运行该应用程序时,按钮被弄乱了,就像屏幕截图中那样。我在按钮上应用了一些约束enter image description here

最佳答案

您可以使用 NSLayoutConstraint ,当您点击下一步按钮时将其更改为 LeadingConstaint

代码:

- (void)changeSelectedByTapView:(UIView *)tapView {
_currentSelectedView = tapView;
self.lineImageViewLeadingConstaint.constant = tapView.frameX;
self.lineImageViewWidthConstaint.constant = tapView.width;
[UIView animateWithDuration:0.5f animations:^{
[self.lineImageView.superview layoutIfNeeded];
}];
}

关于ios - 将 UIView 从一个选项卡移动到另一个选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31556190/

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