OGeek|极客世界-中国程序员成长平台

标题: ios - 将 UIView 从一个选项卡移动到另一个选项卡 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:52
标题: ios - 将 UIView 从一个选项卡移动到另一个选项卡

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

View Controller 是 600x600 并且下一个按钮是200x0 所以如果我将 UIView 的值更改为 200,这将是硬编码的,它会根据屏幕大小而改变。我希望它是完美的,不知道任何其他方式。

更新:
我正在使用 AutoLayout 所以为此,我使用了 [self.buttonBottomView setTranslatesAutoresizingMaskIntoConstraints:YES]; ,当我运行应用程序时,按钮就像屏幕截图中一样乱七八糟。我在按钮上应用了一些 constraintsenter image description here



Best Answer-推荐答案


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

代码:

- (void)changeSelectedByTapViewUIView *)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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4