//ide
// ViewController.m動畫
// 動畫spa
//.net
// Created by DC017 on 15/12/31.3d
// Copyright © 2015年 DC017. All rights reserved.orm
//get
#import "ViewController.h"it
@interface ViewController ()io
{class
UIView * view1;
UIView * view2;
int i;
}
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
i=0;
[self layout];
}
-(void)layout{
view1=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 375, 200)];
view1.backgroundColor=[UIColor orangeColor];
[self.view addSubview:view1];
view2=[[UIView alloc]initWithFrame:CGRectMake(0, 467, 375, 200)];
view2.backgroundColor=[UIColor orangeColor];
[self.view addSubview:view2];
UIButton * button=[[UIButton alloc]initWithFrame:CGRectMake(375/2.0-30, 330, 60, 20)];
[button setTitle:@"動畫" forState:UIControlStateNormal];
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(donghua) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
UILabel * label1=[[UILabel alloc]initWithFrame:CGRectMake(375/2.0-50,100 , 100, 20)];
label1.textColor=[UIColor redColor];
label1.text=@"哈哈!!!!";
[view1 addSubview:label1];
UILabel * label2=[[UILabel alloc]initWithFrame:CGRectMake(375/2.0-50,100 , 100, 20)];
label2.textColor=[UIColor redColor];
label2.text=@"呵呵!!!!";
[view2 addSubview:label2];
}
-(void)donghua{
if (i==0) {
[UIView beginAnimations:@"move" context:nil];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self];
//改變它的frame的x,y的值
view1.frame=CGRectMake(0,-200, 375,200);
view2.frame=CGRectMake(0, 667, 375, 200);
[UIView commitAnimations];
i=1;
}else if (i==1){
[UIView beginAnimations:@"move" context:nil];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self];
//改變它的frame的x,y的值
view1.frame=CGRectMake(0,0, 375,200);
view2.frame=CGRectMake(0, 467, 375, 200);
[UIView commitAnimations];
i=0;
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end