该app为应用的功能为动态移动动画
现版本 SDK 8.4 Xcode
运行Xcode 选择 Create a new Xcode project ->Single View Application 命名 movingImage
(1) 在xCode打开 ViewController.m 文件
(红色为所添加的代码)
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
//[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//定义图片的位置和尺寸,位置: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)];
//设定图片名称,lovely mouse.png已经存在,拖放添加图片文件到项目Supporting Files文件夹中
[subView setImage:[UIImage imageNamed:@"lovely mouse.png"]];
//启用动画移动
[UIImageView beginAnimations:nil context:NULL];
//移动时间4秒
[UIImageView setAnimationDuration:4];
//图片持续移动
[UIImageView setAnimationBeginsFromCurrentState:YES];
//重新定义图片的位置和尺寸,位置
subView.frame = CGRectMake(100.0, 150.0, 200.0, 160.0);
//完成动画移动
[UIImageView commitAnimations];
//在 View 中加入图片 subview
[self.view addSubview:subView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
(6)模拟器效果图
本文源于网上博客教程,经过本人修改和测试。原blog地址 http://blog.sina.com.cn/s/blog_5fae23350100dvx9.html