ios7 UIAnimation

来源:互联网 发布:淘宝上怎么找卖片的 编辑:程序博客网 时间:2024/06/05 10:58
 //视图1
    
    UIView *rootview01 = [[UIView alloc]init];
    
    rootview01.tag = 101;
    
    rootview01.frame = CGRectMake(0, 20, 320, 460);
    
    rootview01.backgroundColor = [UIColor greenColor];
    
    [self.window addSubview:rootview01];
    [rootview01 release];
    //视图1上的按钮
    UIButton *btn01 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    btn01.frame =CGRectMake(100, 200, 80, 40);
    
    [btn01 setTitle:@"视图一" forState:UIControlStateNormal];
    
    [btn01 addTarget:self action:@selector(pressBtn01) forControlEvents:UIControlEventTouchUpInside];
    
    [rootview01 addSubview:btn01];
    
   //视图2
    UIView *rootview02 = [[UIView alloc]init];
    
    rootview02.tag = 102;
    
    rootview02.frame = CGRectMake(320, 20, 320, 460);
    
    rootview02.backgroundColor = [UIColor blueColor];
    
    [self.window addSubview:rootview02];
    [rootview02 release];
    //视图2上的按钮
    UIButton *btn02 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    btn02.frame =CGRectMake(100, 200, 80, 40);
    
    [btn02 setTitle:@"视图二" forState:UIControlStateNormal];
    
    [btn02 addTarget:self action:@selector(pressBtn02) forControlEvents:UIControlEventTouchUpInside];
    
    [rootview02 addSubview:btn02];

    //视图3
    UIView *rootview03 = [[UIView alloc]init];
    
    rootview03.tag = 103;
    
    rootview03.frame = CGRectMake(0, -480, 320, 460);
    
    rootview03.backgroundColor = [UIColor yellowColor];
    
    [self.window addSubview:rootview03];
    [rootview03 release];
    //视图3上的按钮
    
    UIButton *btn03 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    btn03.frame =CGRectMake(100, 200, 80, 40);
    
    [btn03 setTitle:@"视图三" forState:UIControlStateNormal];
    
    [btn03 addTarget:self action:@selector(pressBtn03)forControlEvents:UIControlEventTouchUpInside];
    
    [rootview03 addSubview:btn03];

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;

-(void)pressBtn01
{
    UIView *rootView01 = [self.window viewWithTag:101];
    UIView *rootView02 = [self.window viewWithTag:102];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.5];
    
    rootView01.frame = CGRectMake(-320, 20, 320, 460);
    rootView02.frame = CGRectMake(0, 20, 320, 460);
    
    [UIView commitAnimations];

    
}
-(void)pressBtn02
{
    UIView *rootView02 = [self.window viewWithTag:102];
    UIView *rootView03 = [self.window viewWithTag:103];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1.5];
    
    rootView02.frame = CGRectMake(0, 480, 320, 460);
    rootView03.frame = CGRectMake(0, 20, 320, 460);
    
    [UIView commitAnimations]
;
 
    
}-(void)pressBtn03
{
     UIView *rootView03 = [self.window viewWithTag:103];
     [rootView03 removeFromSuperview];
}