iPhone开发之开关门动画效果

shoxuian

-(void)viewWillAppear:(BOOL)animated{
    for (UIButton *btn in self.view.subviews) {
        btn.alpha = 0;
        switch (btn.tag) {
            case 1:
                btn.frame = CGRectMake(-171, 0, 171, 179);
                break;
            case 2:
                btn.frame = CGRectMake(320, 0, 149, 179);
                break;
            case 3:
                btn.frame = CGRectMake(-140, 480, 140, 213);
                break;
            case 4:
                btn.frame = CGRectMake(320, 480, 182, 145);
                break;
            case 5:
                btn.frame = CGRectMake(150, 480, 89, 70);
                break;
            case 6:
                btn.frame = CGRectMake(320, 480, 95, 70);
                break;
                
            default:
                break;
        }
    }
    
    [UIView beginAnimations:@"animationID" context:nil];
    [UIView setAnimationDuration:1.0f];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationRepeatAutoreverses:NO];
    
    
    for (UIButton *btn in self.view.subviews) {
        btn.alpha = 1;
        switch (btn.tag) {
            case 1:
                btn.frame = CGRectMake(0, 28, 171, 179);
                break;
            case 2:
                btn.frame = CGRectMake(171, 28, 149, 179);
                break;
            case 3:
                btn.frame = CGRectMake(0, 206, 140, 213);
                break;
            case 4:
                btn.frame = CGRectMake(140, 206, 182, 145);
                break;
            case 5:
                btn.frame = CGRectMake(140, 349, 89, 70);
                break;
            case 6:
                btn.frame = CGRectMake(229, 349, 95, 70);
                break;
                
            default:
                break;
        }
    }
    
    [UIView commitAnimations];
}

//在viewDidLoad中对应坐标加入按钮、图片
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];

    //界面设计
    UIButton *btnSchoolSearch = [UIButton buttonWithType:UIButtonTypeCustom];
    btnSchoolSearch.frame = CGRectMake(0, 28, 171, 179);
    btnSchoolSearch.tag = 1;
    [btnSchoolSearch addTarget:self action:@selector(toSchoolSearch) forControlEvents:UIControlEventTouchUpInside];
    [btnSchoolSearch setTitle:@"驾校查询" forState:UIControlStateNormal];
    [btnSchoolSearch setImage:[UIImage imageNamed:@"HomePage_SchoolSearch.png"] forState:UIControlStateNormal]; 
    [self.view addSubview:btnSchoolSearch];
    [btnSchoolSearch release];
    
    
    UIButton *btnZYgroupShopping = [UIButton buttonWithType:UIButtonTypeCustom];
    btnZYgroupShopping.frame = CGRectMake(171, 28, 149, 179);
    btnZYgroupShopping.tag = 2;
    [btnZYgroupShopping addTarget:self action:@selector(toZYGroupShoping) forControlEvents:UIControlEventTouchUpInside];
    [btnZYgroupShopping setTitle:@"众悦团购" forState:UIControlStateNormal];
    [btnZYgroupShopping setImage:[UIImage imageNamed:@"HomePage_YgroupShoping.png"] forState:UIControlStateNormal];
    [self.view addSubview:btnZYgroupShopping];
    [btnZYgroupShopping release];
    
    
    UIButton *btnTesting = [UIButton buttonWithType:UIButtonTypeCustom];
    btnTesting.frame = CGRectMake(0, 206, 140, 213);
    btnTesting.tag = 3;
    [btnTesting addTarget:self action:@selector(toTesting) forControlEvents:UIControlEventTouchUpInside];
    [btnTesting setTitle:@"交规考试" forState:UIControlStateNormal];
    [btnTesting setImage:[UIImage imageNamed:@"HomePage_Testing.png"] forState:UIControlStateNormal];
    [self.view addSubview:btnTesting];
    [btnTesting release];
    
    
    UIButton *btnLearningWay = [UIButton buttonWithType:UIButtonTypeCustom];
    btnLearningWay.frame = CGRectMake(140, 206, 182, 145);
    btnLearningWay.tag = 4;
    [btnLearningWay addTarget:self action:@selector(toLearningWay) forControlEvents:UIControlEventTouchUpInside];
    [btnLearningWay setTitle:@"驾考秘笈" forState:UIControlStateNormal];
    [btnLearningWay setImage:[UIImage imageNamed:@"HomePage_LearningWay.png"] forState:UIControlStateNormal];
    [self.view addSubview:btnLearningWay];
    [btnLearningWay release];
    
    
    UIButton *btnSingleCentre = [UIButton buttonWithType:UIButtonTypeCustom];
    btnSingleCentre.frame = CGRectMake(140, 349, 89, 70);
    btnSingleCentre.tag = 5;
    [btnSingleCentre addTarget:self action:@selector(toSingleCentre) forControlEvents:UIControlEventTouchUpInside];
    [btnSingleCentre setTitle:@"个人中心" forState:UIControlStateNormal];
    [btnSingleCentre setImage:[UIImage imageNamed:@"HomePage_SingleCentre.png"] forState:UIControlStateNormal];
    [self.view addSubview:btnSingleCentre];
    [btnSingleCentre release];
    
    
    UIButton *btnMore = [UIButton buttonWithType:UIButtonTypeCustom];
    btnMore.frame = CGRectMake(229, 349, 95, 70);
    btnMore.tag = 6;
    [btnMore addTarget:self action:@selector(toMore) forControlEvents:UIControlEventTouchUpInside];
    [btnMore setTitle:@"更多" forState:UIControlStateNormal];
    [btnMore setImage:[UIImage imageNamed:@"HomePage_More.png"] forState:UIControlStateNormal];
    [self.view addSubview:btnMore];
    [btnMore release];
}
 
  

 

 

转载于:https://www.cnblogs.com/ios-wmm/archive/2012/08/20/2647115.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值