【问题标题】:Animating a UIImageView off the screen使 UIImageView 离开屏幕的动画
【发布时间】:2011-05-31 13:27:22
【问题描述】:

我有一个UIImageView,我需要在屏幕外设置动画。我通过在 1 秒的动画块中将帧调整为 0 来做到这一点。如果我不考虑作为缩放类型之一的内容类型,它会按照我的意愿缩小到 0,但它会在调整到新的帧大小时挤压图像。 我需要它来剪掉底部。我将内容类型更改为左上角,这导致它不执行任何操作。
我在这里想念什么?

这是动画块代码。

// Change frame height.
[UIView animateWithDuration:1.0f
                 animations:^ {
                     // Animate the frame off the screen
                     _closeImage.frame = CGRectMake(_closeImage.frame.origin.x, _closeImage.frame.origin.y, _closeImage.frame.size.width, 0);
                 }
 ];

【问题讨论】:

  • 内容类型是什么意思?
  • 他的意思是缩放模式。 @btate,尝试其他 scaleModes。

标签: iphone ios ipad uiview uiimageview


【解决方案1】:

您想更改scaleMode 属性。如果您希望它在正确缩放时缩小,您可以将其更改为宽高比。否则,您可以尝试其他一些。

编辑:

根据您的评论,您需要设置clipsToBounds 属性。

【讨论】:

  • @Moshe 你的意思是contentMode
  • 我正在更改内容模式。如果我做的不是缩放之一,那么框架高度根本不会改变。我目前正在使用左上角。 _closeImage.contentMode = UIViewContentModeTopLeft;
  • 你是在动画块内部还是外部更改它?此外,请尝试在更改内容模式后立即重新加载图像,然后再制作动画。强制使用正确的模式可能会有所帮助。
  • 我在动画块外做。
  • _closeImage.frame = self.frame; _closeImage.contentMode = UIViewContentModeTopLeft; // Add as subview [self.superview addSubview:_closeImage]; // Remove this from the super view [self removeFromSuperview]; // Change frame height. [UIView animateWithDuration:1.0f animations:^ { // Animate the frame off the screen _closeImage.frame = CGRectMake(_closeImage.frame.origin.x, _closeImage.frame.origin.y, _closeImage.frame.size.width, 0); } ];
【解决方案2】:

你可以试试:

    // Change frame placement.
[UIView animateWithDuration:1.0f
                 animations:^ {
                     // Animate the frame off the screen
                     _closeImage.frame = CGRectMake(_closeImage.frame.origin.x, _parentView.frame.size.height, _closeImage.frame.size.width, _closeImage.frame.size.height);
                 }
 ];

_parentView 是包含 imageview 的视图...它会从 parentView 滑出,如果您不再使用它,请考虑将其从 superview 中删除...

【讨论】:

  • 父视图顶部有一个工具栏。我正在寻找更多的效果,就好像图像正在滚出并滚入工具栏一样。所以我只需要将帧设置为 0 并裁剪掉任何不适合的内容。
  • 因此将工具栏设置在图像视图的顶部并将图像的原点更改为:CGRectMake(_closeImage.frame.origin.x, -_closeImage.frame.size.height, _closeImage.frame。尺寸.宽度,_closeImage.frame.size.height);当你可以将它移出屏幕时为什么要缩小图像......
猜你喜欢
  • 1970-01-01
  • 2012-10-22
  • 1970-01-01
  • 2019-04-17
  • 1970-01-01
  • 1970-01-01
  • 2011-05-28
  • 2021-12-21
  • 2020-07-19
相关资源
最近更新 更多