【IOS实例小计】图像移动--可扩展为动态实现图标变化

时间:2022-06-01 21:24:35

预备知识:

1.页面切换:

从一个ViewController切换到另一个ViewController有下面几种方法:

(1)self.view addSubview:(加载的新页面);
     相应的 [self.view removeFromSuperview];可以回到起始页面
(2)self.view insertSubview:(加载的新页面) atIndex:n;
对n的解释:页面都是层次叠加的,n表示加载到那一层上面
(3) self presentModalViewController:(加载的新页面)  animated:

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

效果:

【IOS实例小计】图像移动--可扩展为动态实现图标变化

【IOS实例小计】图像移动--可扩展为动态实现图标变化

参考:

http://blog.sina.com.cn/s/blog_6700ebf201016ios.html

http://www.cnblogs.com/xingchen/archive/2011/08/15/2139771.html