足球游戏_中国足彩网¥体育资讯$

用Animation实现iphone动画效果
来源:易贤网 阅读:986 次 日期:2014-11-04 11:09:15
温馨提示:易贤网小编为您整理了“用Animation实现iphone动画效果”,方便广大网友查阅!

1、写了一个小Demo,实现上下移动的效果图:

名单1

名单2

名单3

主要代码如下:

- (IBAction)upChange:(id)sender {

if (typeView == down) {

[self.downBtn setHidden:NO];

[self.upBtn setHidden:NO];

[UIView animateWithDuration:0.5 animations:^{

self.upView.center = CGPointMake(self.upView.center.x, 0);

self.downView.center = CGPointMake(self.downView.center.x, (self.upView.frame.size.height+self.downView.frame.size.height)/2);

}];

typeView = middle;

}else if(typeView == middle){

[self.downBtn setHidden:NO];

[self.upBtn setHidden:YES];

[UIView animateWithDuration:0.5 animations:^{

self.upView.center = CGPointMake(self.upView.center.x, -(self.upView.frame.size.height/2));

self.downView.center = CGPointMake(self.downView.center.x, self.downView.frame.size.height/2);

}];

typeView = up;

}

}

- (IBAction)downChange:(id)sender {

if (typeView == middle) {

[self.downBtn setHidden:YES];

[self.upBtn setHidden:NO];

[UIView animateWithDuration:0.5 animations:^{

self.upView.center = CGPointMake(self.upView.center.x, self.upView.frame.size.height/2);

self.downView.center = CGPointMake(self.downView.center.x, self.upView.frame.size.height+self.downView.frame.size.height/2);

}];

typeView = down;

}else if(typeView == up)

{

[self.downBtn setHidden:NO];

[self.upBtn setHidden:NO];

[UIView animateWithDuration:0.5 animations:^{

self.upView.center = CGPointMake(self.upView.center.x, 0);

self.downView.center = CGPointMake(self.downView.center.x, (self.upView.frame.size.height+self.downView.frame.size.height)/2);

}];

typeView = middle;

}

}

这是主要的代码,另外还有一些需要注意的一些小细,如你的两个view的大小,需要计算出精确位置。

下面开始学习[UIView animateWithDuration]方法的使用:

函数原型:

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0); // delay = 0.0, options = 0, completion = NULL

duration:动画持续时间

animations:该代码儿块中是所有view要完成的动画的所有属性的定义;

还有另外两个函数:

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);// delay = 0.0, options = 0

options:是动画执行的选项

completion:是动画完成以后所要执行的代码块儿。

中国足彩网信息请查看IT技术专栏

中国足彩网信息请查看技术文章
易贤网手机网站地址:用Animation实现iphone动画效果
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 足球游戏_中国足彩网¥体育资讯$ 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标