使用 AutoLayout 缩放图像

Scale an image with AutoLayout

所以我想在屏幕的下半部分显示一个图像,然后将其设置为较小比例的动画并将其附加到 top/right。抱歉图片粗糙,但这基本上是我想要的:

我想我可以通过限制我的视图的顶部、右侧和纵横比来做到这一点,然后只为我的纵横比约束的变化设置动画。不幸的是,当我执行此操作时,IB 尖叫说我的视图没有合适的 X 值,而当我设置比例动画时,我最终的视图垂直缩小但仍然是全宽。

我希望这是有道理的,并且有人可以帮助我弄清楚如何实现这一目标。

好的,我明白了。看我能不能解释清楚给别人听

位置 1 约束:

  • 左 = 0
  • 右 = 0
  • 底部 = 0
  • 前 = 150

位置 2 约束:

  • 前 = 40
  • SuperView 的纵横比高度为 0.25(我使用 PureLayout 所以 不确定通用样式约束会是什么样子)
  • 看点 与 SuperView 的宽度比 0.25

做我的动画:

- (void)animateAgent
{
    self.agentTop.constant = 40.0;
    [NSLayoutConstraint deactivateConstraints:@[ self.agentBottom, self.agentLeft ]];
    self.agentHeightRatio = [self.agentContainer autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self.animationContainer withMultiplier:0.25];
    self.agentWidthRatio = [self.agentContainer autoMatchDimension:ALDimensionWidth toDimension:ALDimensionHeight ofView:self.animationContainer withMultiplier:0.25];

    [self.view setNeedsLayout];
    [UIView animateWithDuration:0.3 animations:^{
    [self.view layoutIfNeeded];
    }];
}