Ios UIImageView动画持续时间(带淡入效果)

Ios UIImageView动画持续时间(带淡入效果),ios,objective-c,uiimageview,Ios,Objective C,Uiimageview,我正在寻找一种(非常)简单的方法来在动画持续时间内交叉淡入淡出图像。我试着使用NSTimer和我在这里找到的一些其他东西,但没有任何解决方案满足或帮助我 我在一个方法中创建了这个东西(没有注释) }-(UIImageView*)播放顺序 { 如果(_playSequence==nil) { NSArray*structureArray=self.ContentManager.ImageViewControllerSize; NSMutableArray*structuresToPlay=[[NS

我正在寻找一种(非常)简单的方法来在动画持续时间内交叉淡入淡出图像。我试着使用NSTimer和我在这里找到的一些其他东西,但没有任何解决方案满足或帮助我

我在一个方法中创建了这个东西(没有注释)

}

-(UIImageView*)播放顺序
{
如果(_playSequence==nil)
{
NSArray*structureArray=self.ContentManager.ImageViewControllerSize;
NSMutableArray*structuresToPlay=[[NSMutableArray alloc]init];
//走通电流采集
对于(NSInteger i=0;i<[self.currentCollection count];i++)
{
NSInteger index=[[self.currentCollection objectAtIndex:i]integerValue];
[structuresToPlay addObject:[UIImage ImageName:[structureArray objectAtIndex:index]];
}
_playSequence=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,1024,768)];
}
_playSequence.animationImages=structuresToPlay;
_playSequence.animationDuration=5*structuresToPlay.count;
[_播放序列开始播放];
返回播放顺序;
}

这里是切换到UIImageView的另一种方式,添加淡入淡出并不困难

- (void) performAnimationOfFrameAtIndex:(NSNumber*)indexNum
{
    int index = indexNum.intValue;

    BOOL completedSequece = index >= [self.frames count];

    if (completedSequece) return;

    UIImageView *imgIn;
    UIImageView *imgOut;

    if (index % 2 == 0) {
        imgIn = self.animationImageViewOne;
        imgOut = self.animationImageViewTwo;
    }
    else {
        imgIn = self.animationImageViewTwo;
        imgOut = self.animationImageViewOne;
    }

    imgIn.image = [self.frames objectAtIndex:index];
    [self.view sendSubviewToBack:imgOut];

    double speed = 0.1;

    [self performSelector:@selector(performAnimationOfFrameAtIndex:) withObject:[NSNumber numberWithInt:index + 1] afterDelay:speed];
}

我创建了一个完全符合您描述的项目(类似于UIImageView动画序列的效果,但图像之间有交叉淡入淡出)

该项目位于github上:

您需要有2个图像视图

我使用的技巧是将它们堆叠在一起,然后简单地从alpha 1->0设置顶部图像视图的动画,然后在顶部图像视图中切换图像并从alpha 0->1.0设置动画,从而显示新图像


该项目仅使用5帧演示变形过渡。每个帧都标有一个数字,以便您可以看到帧的变化。它有一个开关,可以打开或关闭交叉衰落。

您想要达到的确切效果是什么?要交叉淡入淡出图像,我通常使用两个
UIImageView
,并在动画的
completion
块中加载新图像。您是否尝试过像这样的UIView动画-->[UIView animateWithDuration:1.0f动画:^{//您的动画}完成:^(BOOL completedt){}];是的,我是说交叉淡入淡出,是的,我试过UIView动画。为了显示图像,我使用UIViewController+knsemimodel-也许问题出在这里?你能描述一下当前代码的效果吗?只有简单的幻灯片放映。舒尔它工作得很好,但对眼睛来说很难:)嗯。。。交叉褪色的解决方案在哪里?
- (void)justPlaySelection
{
    UIView *justPlaySelection = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];

    // some background music code ...

    // add play sequence
    [justPlaySelection addSubview:self.playSequence];

    // add close button
    // { ... }

    [self presentSemiView:justPlaySelection];
- (UIImageView *)playSequence
{
   if (_playSequence == nil)
    {
     NSArray *structureArray = self.contenManager.ImageViewControllerSize;
        NSMutableArray *structuresToPlay = [[NSMutableArray alloc] init];

        // walk thru current collection
        for(NSInteger i = 0; i < [self.currentCollection count]; i++)
        {
            NSInteger index = [[self.currentCollection objectAtIndex:i] integerValue];
            [structuresToPlay addObject:[UIImage imageNamed:[structureArray objectAtIndex:index]]];
        }

        _playSequence = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];

    }

    _playSequence.animationImages = structuresToPlay;
    _playSequence.animationDuration = 5 * structuresToPlay.count;

    [_playSequence startAnimating];
    return _playSequence;

}
- (void) performAnimationOfFrameAtIndex:(NSNumber*)indexNum
{
    int index = indexNum.intValue;

    BOOL completedSequece = index >= [self.frames count];

    if (completedSequece) return;

    UIImageView *imgIn;
    UIImageView *imgOut;

    if (index % 2 == 0) {
        imgIn = self.animationImageViewOne;
        imgOut = self.animationImageViewTwo;
    }
    else {
        imgIn = self.animationImageViewTwo;
        imgOut = self.animationImageViewOne;
    }

    imgIn.image = [self.frames objectAtIndex:index];
    [self.view sendSubviewToBack:imgOut];

    double speed = 0.1;

    [self performSelector:@selector(performAnimationOfFrameAtIndex:) withObject:[NSNumber numberWithInt:index + 1] afterDelay:speed];
}