如何在动画iPhone左到右的观点? [英] How to animate the view Left to Right in iPhone?

查看:357
本文介绍了如何在动画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.

这篇关于如何在动画iPhone左到右的观点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆