How to fadein and fadeout in single UIView?

2019-08-30 04:49发布

example i try to change cell.accessoryView from picture1 to picture2 by fadein

but my problem is i only have one accessoryView(one UIView)

any idea?

标签: iphone uiview
2条回答
Ridiculous、
2楼-- · 2019-08-30 05:17

If you want a fade, you'll have to modify your accessory view rather than reset cell.accessoryView. The simplest approach may be to give your accessory two subviews, one each for picture1 and picture2.

UIImageView *imageView1 = [[[UIImageView alloc] init] autorelease];
UIImageView *imageView2 = [[[UIImageView alloc] init] autorelease];
imageView2.alpha = 0;
[cell.accessoryView addSubview:imageView1];
[cell.accessoryView addSubview:imageView2];

Then do the following to fade between:

[UIView beginAnimations:@"" context:nil];
imageView1.alpha = 0;
imageView2.alpha = 1;
[UIView commitAnimations];
查看更多
手持菜刀,她持情操
3楼-- · 2019-08-30 05:43

if i understood your question properly...

you can try something like

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

}
查看更多
登录 后发表回答