如何在单个UIView中淡化和淡出?

RAG*_*poR 0 iphone uiview

例如,我试图通过fadein将cell.accessoryView从picture1更改为picture2

但我的问题是我只有一个accessoryView(一个UIView)

任何的想法?

Mih*_*hta 6

如果我理解你的问题......

你可以试试像

    //-------fade out

- (void)animateFadingOut{

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:1.0];

[UIView setAnimationDidStopSelector:@selector(animateFadingIn)];

[UIView setAnimationDelegate:self];

//set transformation
[cell.accessoryView addSubview:NewImgeView];
cell.accessoryView.alpha = 0.0;

[UIView commitAnimations];

}
-(void)animateFadingIn{

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:1.0];

[UIView setAnimationDelegate:self];

//set transformation
cell.accessoryView.alpha = 1.0;

[UIView commitAnimations];

}
Run Code Online (Sandbox Code Playgroud)


Tom*_*Tom 5

如果你想要淡入淡出,你将不得不修改你的配件视图而不是重置cell.accessoryView.最简单的方法可能是为您的附件提供两个子视图,分别为picture1和picture2.

UIImageView *imageView1 = [[[UIImageView alloc] init] autorelease];
UIImageView *imageView2 = [[[UIImageView alloc] init] autorelease];
imageView2.alpha = 0;
[cell.accessoryView addSubview:imageView1];
[cell.accessoryView addSubview:imageView2];
Run Code Online (Sandbox Code Playgroud)

然后执行以下操作以淡化:

[UIView beginAnimations:@"" context:nil];
imageView1.alpha = 0;
imageView2.alpha = 1;
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)