#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 100)];
view1.tag = 1; //标示一个视图对象
// view1 = [self.view viewWithTag:1]; //可以通过tag查找view
view1.backgroundColor = [UIColor redColor];
view1.clipsToBounds = YES; //剪切掉视图外的内容
[self.view addSubview:view1];
[view1 release];
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 200)];
view2.tag = 2;
view2.backgroundColor = [UIColor yellowColor];
[view1 addSubview:view2];
view2.alpha = 0.5; //透明度
[view2 release];
UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
view3.tag = 2;
view3.backgroundColor = [UIColor greenColor];
[view1 addSubview:view3];
[view3 release];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(90,400, 140, 40);
[button setTitle:@"change" forState:UIControlStateNormal];
[button addTarget:self action:@selector(changeView) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(5, 0, 50, 30)];
label.text = @"jianguo";
label.textColor = [UIColor whiteColor];
label.font = [UIFont fontWithName:nil size:14];
[view3 addSubview:label];
}
-(void)changeView{
NSLog(@"print");
UIView *vv = [self.view viewWithTag:2];
[self.view addSubview:vv];
NSLog(@"%@",vv);
[UIView beginAnimations:nil context:NULL]; //需要设置代理时
[UIView setAnimationDuration:5]; //设置动画的持续时间
[UIView setAnimationDelay:1]; //设置动画的延迟时间
vv.alpha = 0.0; //淡出
// vv.backgroundColor = [UIColor blueColor];
vv.alpha = 1.0;
[UIView commitAnimations]; //动画结束
// [UIView beginAnimations:nil context:NULL];
// [UIView setAnimationDuration:10];
// [UIView setAnimationDelay:5];
// vv.alpha = 1.0;
// [UIView setAnimationCurve:UIViewAnimationCurveLinear]; //动画的速率
// vv.center = CGPointMake(300, 500); //移动的位置
// [UIView commitAnimations];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end