我在扩展 UIView 的类中有动画代码:
// Start Animation Block
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:[self superview] cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
//int nextView = currentView + 1;
// Animations
[[self superview] exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
//And so I would do: [[self superview exchangeSubviewAtIndex:currentView withSubviewAtIndex:nextView];
//Doesn't work because curentView is not global... with each instance of a class it's reset to what it's instanciated to.
//currentView++;
// Commit Animation Block
[UIView commitAnimations];
此动画代码适用于两个视图。但我试图为许多观点这样做。我尝试通过添加一个全局变量(nextview 索引和 currentView 索引),但这不起作用,因为每个自定义视图类都有它自己的实例并且这些变量不共享。
有谁知道我怎样才能完成我想做的事情?
谢谢!
编辑:如果我可以使用 [self superview] 访问当前视图和下一个视图的索引,我将能够做到这一点。有一些方法可以做到这一点吗?