第四天 图像移动《苹果iOS实…

来源:互联网 发布:apache 图片压缩 编辑:程序博客网 时间:2024/06/06 03:31
原文地址:图像移动《苹果iOS实例编程入门教程》">第四天 图像移动《苹果iOS实例编程入门教程》作者:苹果iphonesdk

[转载]第四天 <wbr>图像移动《苹果iOS实例编程入门教程》

//iOS SDK 中的 UIImageView动态移动动画

运行安装好的 xCode

选择: File->NewProject.

从 'New Project' 窗口
选择 : iPhone OS->Applications-> Single ViewApplication

命名 : 这里命名为 “movingImage”


//打开 ViewController.m 文件:

 

//解开(void)viewDidLoad

- (void)viewDidLoad {


 

   //定义图片的位置和尺寸,位置:x=10.0f, y=10.0f ,尺寸:x=50.0f,y=40.0f

   UIImageView *subview = [[UIImageView alloc]initWithFrame:

                           CGRectMake(10.0f, 10.0f, 50.0f, 40.0f)];

 

   //设定图片名称,myPic.png已经存在,拖放添加图片文件到image项目文件夹中
    [subviewsetImage:[UIImage imageNamed:@"myPic.png"]];

 

    //启用动画移动
    [UIImageViewbeginAnimations:nil context:NULL];
 
    //移动时间2秒
    [UIImageView setAnimationDuration:2];
 

    //图片持续移动
    [UIImageView setAnimationBeginsFromCurrentState:YES];
 

    //重新定义图片的位置和尺寸,位置
    subview.frame = CGRectMake(60.0, 100.0,200.0, 160.0);
 
    //完成动画移动
    [UIImageViewcommitAnimations];  
    

    //在View 中加入图片 subview 

   [self.View addSubview:subview];

 

   //使用后释放图片, 使用iOS5,对像为iOS4.3以上可以忽略这步骤
    [subviewrelease];

 

}

 

下载今天程序文件: Day04.zip

文章本人经过修改及测试,希望大家多多交流。欢迎转载,但请注明出处,多珍惜别人的劳动成果,谢谢大家。

一切版权归http://blog.sina.com.cn/iphonesdk 所有

//更多关于iPhone编程的内容可以参阅下书,

链接:
欢迎来到 <wbr><wbr>iPhone <wbr><wbr>SDK <wbr><wbr>编程语言 <wbr><wbr>@ <wbr><wbr>sina <wbr><wbr>Blog

 

原创粉丝点击