IOS开发笔记UIView使用animateWithDuration控制页面效果

来源:未知 责任编辑:责任编辑 发表时间:2013-12-06 08:43 点击:

引言:最近学习了一些页面的跳转动画效果。使用的是UIview的animateWithDuration方法。当然之前的beginAnimations也是可以实现的。

 

比如一:从屏幕下部往上渐渐弹出一个图片


[plain] 
-(void) fadeIn 
{    
    CGRect rect = [[UIScreen mainScreen] bounds]; 
      self.view.center = CGPointMake(rect.size.width/2, 720); 
    [UIView animateWithDuration:0.5f animations:^{ 
         self.view.center = CGPointMake(rect.size.width/2, 240+10);   
    } completion:^(BOOL finished) { 
     //   [imageView setImageURL:[NSURL URLWithString:imgUrl]]; 
    }]; 


比如二:再渐渐退回去

[plain] 
-(void) fadeOut 

    CGRect rect = [[UIScreen mainScreen] bounds]; 
    [UIView animateWithDuration:0.5f animations:^{ 
        self.view.center = CGPointMake(rect.size.width/2, 720); 
    } completion:^(BOOL finished) { 
        [imageView cancelImageLoad]; 
        [imageView release]; 
        //[imgUrl release]; 
       // imageView = nil; 
        //imgUrl = nil; 
       // [self.view removeFromSuperview]; 
    }]; 

如果使用beginAnimations就是下面这样的。。。。

[plain]
   CGRect rect = [[UIScreen mainScreen] bounds]; 
   self.myimg.center = CGPointMake(rect.size.width/2, 720); 
   [UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:1.0]; 
 
self.myimg.center = CGPointMake(rect.size.width/2, 720);  
 
[UIView commitAnimations]; 


备注:其实掌握了  self.view.center = CGPointMake(rect.size.width/2, 240+10);
设置其中心点坐标即可。


下面是可以设置动画效果的属性:

frame
bounds
center
transform
alpha
backgroundColor
contentStretch

例如一个视图淡出屏幕,另外一个视图出现的代码:

[UIView animateWithDuration:1.0 animations:^{
        firstView.alpha = 0.0;
        secondView.alpha = 1.0;
}];
completion为动画执行完毕以后执行的代码块
options为动画执行的选项。可以参考这里
delay为动画开始执行前等待的时间

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • Lexical or Preprocessor Issue 'xxx.h
    • ios学习笔记(二)xcode 4.3.2下实现基本交互
    • ios版本的helloworld
    • iphone(object-c) 内存管理(3) 有效的内存管理 前半部分
    • ios学习笔记(一)xcode 4.3.2下创建第一个ios项目
    • IOS类似iphone通讯录TableView的完整demo【附源码】
    • UITableView一些方法
    • [iPhone中级]iPhone团购信息客户端的开发 (二)
    • 如何为Iphone应用创建启动界面
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1