【问题标题】:iOS transform and frame animationiOS 变换和帧动画
【发布时间】:2019-08-22 16:53:16
【问题描述】:

我想将视图框架更改为全屏边界并转换为横向。

我使用了 UIView 动画换帧和视图的变换。

- (void)enterFullScreen {
  CGRect frame = CGRectMake(0, 0, CGRectGetHeight(UIScreen.mainScreen.bounds), CGRectGetWidth(UIScreen.mainScreen.bounds));
  self.originFrame = self.presentView.frame;
  [UIView animateWithDuration:ZXYAnimationDuration animations:^{
    self.presentView.transform = CGAffineTransformMakeRotation(M_PI_2);
    self.presentView.frame = frame;
  } completion:^(BOOL finished) {

  }];
}

- (void)exitFullScreen {
  [UIView animateWithDuration:ZXYAnimationDuration animations:^{
    self.presentView.transform = CGAffineTransformIdentity;
    self.presentView.frame = self.originFrame;
  } completion:^(BOOL finished) {

  }];
}

我希望视图旋转到横向和全屏,但似乎旋转错误。

【问题讨论】:

  • 不要修改框架而是使用自动布局约束
  • 我发现,不能同时修改trasnform和frame,如果我只修改frame或者transform就可以了。

标签: ios animation transform


【解决方案1】:

最后我试了一下,答案是,不要交换宽高,如下图:

- (void)enterFullScreen {
  CGRect frame = CGRectMake(0, 0, CGRectGetWidth(UIScreen.mainScreen.bounds), CGRectGetHeight(UIScreen.mainScreen.bounds));
  self.originFrame = self.presentView.frame;
  [UIView animateWithDuration:ZXYAnimationDuration animations:^{
    self.presentView.transform = CGAffineTransformMakeRotation(M_PI_2);
    self.presentView.frame = frame;
  } completion:^(BOOL finished) {

  }];
}

- (void)exitFullScreen {
  [UIView animateWithDuration:ZXYAnimationDuration animations:^{
    self.presentView.transform = CGAffineTransformIdentity;
    self.presentView.frame = self.originFrame;
  } completion:^(BOOL finished) {

  }];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    • 2021-10-19
    • 1970-01-01
    • 2013-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多