预备知识:
1.页面切换:
从一个ViewController切换到另一个ViewController有下面几种方法:
2.UI动画移动原理:
定义一个起始位置和一个终止位置,使用CGPoint对象来代表,然后定义一个动画,最后提交这个动画,使之在应用运行的状态下实现动画效果。
3.代码:
//
// MoveViewController.h
// ImageView
//
// Created by zhang xujun on 13-9-9.
// Copyright (c) 2013年 zhang xujun. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface MoveViewController : UIViewController
@property (strong,nonatomic) IBOutletUIButton *returnSuperView;
@property (strong,nonatomic) IBOutletUIButton *moveImage;
@property (strong,nonatomic) IBOutletUIImageView *moveImageView;
-(IBAction)returnSuperViewButton:(id)sender;
-(IBAction)move:(id)sender;
@end
// // MoveViewController.m // ImageView // // Created by zhang xujun on 13-9-9. // Copyright (c) 2013年 zhang xujun. All rights reserved. // #import "MoveViewController.h" @interface MoveViewController () @end @implementation MoveViewController @synthesize returnSuperView; @synthesize moveImage; @synthesize moveImageView; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { } return self; } - (void)viewDidLoad { [super viewDidLoad]; moveImageView.frame = CGRectMake(10.0, 10.0, 50.0, 40.0); [self.moveImageView setImage:[UIImage imageNamed:@"卡片燃烧1.png"]]; [self.view addSubview:moveImageView]; } -(void)returnSuperViewButton:(id)sender{ [self.view removeFromSuperview]; } -(void)move:(id)sender{ [UIImageView beginAnimations:nil context:NULL]; [UIImageView setAnimationDuration:2]; [UIImageView setAnimationBeginsFromCurrentState:YES]; moveImageView.frame = CGRectMake(60.0, 100.0, 200.0, 160.0); [UIImageView commitAnimations]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end
效果:
参考:
http://blog.sina.com.cn/s/blog_6700ebf201016ios.html
http://www.cnblogs.com/xingchen/archive/2011/08/15/2139771.html