转载:http://blog.csdn.net/linux_zkf
IOS开发中经常会要求交换两个视图,下面给出简单的以交换两个图片的实例代码
- (void) swapButtonPressed: (id) sender
{
UIView *fron = [[self.view subviews] objectAtIndex:2];
UIView *backt = [[self.view subviews] objectAtIndex:1];
CGContextRef ctx = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:ctx];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:2.0];
front.alpha = 0.0f;
back.alpha = 1.0f;
front.transform = CGAffineTransformMakeScale(0.25f, 0.25f);
back.transform = CGAffineTransformIdentity;
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:2];
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
}