简体   繁体   English

在屏幕外为 UIImageView 设置动画

[英]Animating a UIImageView off the screen

I have a UIImageView that I need to animate off the screen.我有一个UIImageView我需要在屏幕上设置动画。 I'm doing this by adjusting the frame to 0 in a 1 second animation block.我通过在 1 秒 animation 块中将帧调整为 0 来做到这一点。 If I leave the content type alone, which is one of the scaling types, it will shrink to 0 as I want it to, but it will pinch the image as it adjusts to the new frame size.如果我不理会作为缩放类型之一的内容类型,它会按照我的意愿缩小到 0,但它会在调整到新的帧大小时挤压图像。 I need it to just crop the bottom off instead .我需要它来代替裁剪底部 I changed the content type to top left and that causes it to not do anything.我将内容类型更改为左上角,这导致它不执行任何操作。
What am I missing here?我在这里想念什么?

Here's the animation block code.这是 animation 块代码。

// 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);
                 }
 ];

You want to change the scaleMode property.您想要更改scaleMode属性。 You can change it to aspect fit if you want it to shrink while scaling correctly.如果您希望它在正确缩放时缩小,您可以将其更改为宽高比。 Otherwise, you can try some of the other ones.否则,您可以尝试其他一些。

EDIT:编辑:

As per your comment, you need to set the clipsToBounds property.根据您的评论,您需要设置clipsToBounds属性。

You can try with:您可以尝试:

    // 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 is view containing imageview... it will slide off parentView, and consider removing it from superview afterwards if you dont use it anymore... _parentView 是包含 imageview 的视图...它会滑出 parentView,如果您不再使用它,请考虑将其从超级视图中删除...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM