iphone用Animation实现动画效果
1、写了一个小Demo,实现上下移动的效果图:主要代码如下:[cpp]- (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;}}- (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 = NULLduration:动画持续时间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 (补充:移动开发 , IOS ,
上一个:iOS 6版本与之前版本差异总结
下一个:IOS文件操作
- 更多wap疑问解答:
- 新人求助QPainter
- 为什么程序都退出了还可以收到推送?如果大多设备都可以推送那运营商怎么办?
- qt 4.7 sqlserver2000 存储过程调用
- 关于ANDROID4.0.1编译问题!
- Android FrameBuffer读屏幕30秒后mmap失败
- 联通粗定位用java程序如何来请求和接受数据
- 为什么QT运行Android平台的程序时,mouseMoveEvent事件响应的间隔时间很长??????????
- android与PC蓝牙通讯
- 指定大小的label 内容可变,如果内容超出label的宽度,将未能显示的部分显示在另一个label上
- Android调试
- android如何通过wifi连接无线打印机
- 运行程序,release目录下产生一个乱码文件夹
- 分享个某机构最新安卓资料,自己验证了
- service启动不起来,掉不了service connection
- 求助:QT5.0 没有QPrinter吗