【问题标题】:UIView bottom constraint after rotate旋转后的UIView底部约束
【发布时间】:2020-06-28 09:55:01
【问题描述】:

我有 UIProgressView,我已转换(旋转)所以它是垂直的,我的问题是底部约束,因为视图旋转后显示不正确,UIView 和 UIProgressView 的底部没有完全对齐,我也试过了要更改锚点,底部也不能对齐。

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initFlow];
    self._wProgressView = [[UIProgressView alloc] init];
    [self._middleRightView addSubview:self._wProgressView];
    [self._wProgressView setProgress:0.7];
    CGPoint newCenter = self._wProgressView.layer.anchorPoint;
    newCenter.x = 0;
    newCenter.y = 1;
    [self._wProgressView.layer setAnchorPoint:newCenter];
    self._wProgressView.transform = CGAffineTransformRotate(self._wProgressView.transform, -0.5 *M_PI);
//    [self._wProgressView.centerXAnchor constraintEqualToAnchor:self._wProgressView.superview.centerXAnchor].active = YES;
    self._wProgressView.translatesAutoresizingMaskIntoConstraints = NO;
    [self._wProgressView.bottomAnchor constraintEqualToAnchor:self._wImageView.bottomAnchor].active = YES;
    [self._wProgressView.widthAnchor constraintEqualToAnchor:self._wProgressView.superview.heightAnchor multiplier:0.5].active = YES;
    [self._wProgressView.heightAnchor constraintEqualToAnchor:self._wProgressView.superview.widthAnchor constant:0.8].active = YES;
    //= self._wProgressView.superview.centerXAnchor;

}

【问题讨论】:

  • 你没有显示任何关于_middleRightView_wImageView 的信息,所以你要做什么并不完全清楚......你能发布一张你的目标是什么的图片吗?

标签: ios objective-c cocoa-touch uiview


【解决方案1】:

我让它这样工作:

你应该只给 UIProgressView 的高度、宽度和中心 x 和 y 约束到 UIView 关系

UIProgressView 不需要给出底部约束

这对我有用,希望对您有所帮助...!

【讨论】:

  • 它们的高度不同,所以中心 Y 和 X 无济于事
  • 好的,您应该先尝试删除 UIProgressView 的所有约束,然后在延迟 0.1 秒后旋转,并为 UIProgressView 提供约束并调用 layoutIfNeeded()
  • 更优雅的方式?
  • 否,当 iphone 处于横向时它不会工作
猜你喜欢
  • 1970-01-01
  • 2013-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-02
  • 1970-01-01
  • 2017-05-15
相关资源
最近更新 更多