gpt4 book ai didi

iphone - UIView 动画问题,当尝试不对图像进行动画处理时

转载 作者:行者123 更新时间:2023-11-28 18:25:26 24 4
gpt4 key购买 nike

我必须放映图片幻灯片。但有一段时间我只知道当前和以前的图像(由于内存管理)。我需要用动画显示下一张图片(用户可以选择动画类型)。但是我看不到动画,只是出现了没有动画的新图像。这是我的代码:

    UIImageView *prevImageView = [self getImageViewWithIndex:currentIndex];
UIImageView *nowImageView = [self getImageViewWithIndex:newIndex];

currentIndex = newIndex;
[UIView animateWithDuration:4 delay:0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
[slideShowView addSubview:nowImageView];
} completion:^(BOOL finished) {
[prevImageView removeFromSuperview];
}];

我尝试了不同的动画选项。尝试将新图像设置为现有 ImageView

nowImageView.image = newImage;

但这并没有帮助。

最佳答案

添加或删除 View 或设置 UIImageView 的图像在 animateWithDuration:... 中不可设置动画。 .

transitionWithView:...

您可能尝试做的是使用 UIView 转换(因为您指定了转换选项)。那么你应该使用

transitionWithView:duration:options:animations:completion:

相反,像这样:

[UIView transitionWithView:slideShowView
duration:4.0
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^
{
[prevImageView removeFromSuperview];
[slideShowView addSubview:nowImageView];
}
completion:NULL]; // You don't need the completion if you remove the previous image in the animation block.

animateWithDuraion:...

如果你真的想使用 animateWithDuraion:... (也许有其他动画同时发生)那么你将不得不为一些其他属性设置动画,比如 alpha您要添加的 View 的一部分,以使其淡入。更改代码以执行此操作看起来像这样。

UIImageView *prevImageView = [self getImageViewWithIndex:currentIndex];
UIImageView *nowImageView = [self getImageViewWithIndex:newIndex];

currentIndex = newIndex;
[slideShowView addSubview:nowImageView];
nowImageView.alpha = 0.0;
[UIView animateWithDuration:4
animations:^
{
nowImageView.alpha = 1.0;
}
completion:^(BOOL finished)
{
[prevImageView removeFromSuperview];
}];

关于iphone - UIView 动画问题,当尝试不对图像进行动画处理时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11029005/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com