如何在动画iPhone左到右的观点?
问题描述:
如何动画从左到右视图过渡(类似推视图)。当我按一下按钮,认为应该从过渡左向右。所以,请指导我,给一些示例的链接。
How to animate the view transition left to right(Similar push view). When i click the button, the view should be transited from left to right. So please guide me and give some sample links.
感谢。
答
假设你想从右侧推视图2代替厂景。
Suppose that you want to push view2 from the right to replace view1.
// Set up view2
view2.frame = view1.frame;
view2.center = CGPointMake(view1.center.x + CGRectGetWidth(view1.frame), view1.center.y);
[view1.superview addSubview: view2];
// Animate the push
[UIView beginAnimations: nil context: NULL];
[UIView setAnimationDelegate: self];
[UIView setAnimationDidStopSelector: @selector(pushAnimationDidStop:finished:context:)];
view2.center = view1.center;
view1.center = CGPointMake(view1.center.x - CGRectGetWidth(view1.frame), view1.center.y);
[UIView commitAnimations];
然后(可选)实现此方法从视图层次结构中删除厂景:
Then (optionally) implement this method to remove view1 from the view hierarchy:
- (void) pushAnimationDidStop: (NSString *) animationID finished: (NSNumber *) finished context: (void *) context {
[view1 removeFromSuperview];
}
在该动画的委托方法你可能还需要释放厂景,并设置其参考为零,这取决于你是否需要转型后各地保持它。
In that animation delegate method you may also want to release view1 and set its reference to nil, depending on whether you need to keep it around after the transition.