Sportica   Sportica

UIBotton UIlabel Ios 下拉框

//下拉列表动画加载
-(void)dropDownListAnimation
{
    SchoolInHandAppDelegate *app = [[UIApplication sharedApplication]delegate];
    //每行的高度
    everyListHight = 30;
    listHight = userCountInFile*everyListHight;
    presstimes ++;
    if(_dropDownbackView ==nil)
    {
        _dropDownbackView = [[UIScrollView alloc]init];
        [_dropDownbackView autorelease];
    }
    _dropDownbackView.frame = CGRectMake(49, 180, 223, listHight);
    [self.view addSubview:_dropDownbackView];
    
    if(_dropDownListView==nil)
    {
        _dropDownListView = [[UIScrollView alloc]init];
        [_dropDownListView autorelease];
    }
    _dropDownListView.frame = CGRectMake(0, 0, 223, listHight);
    //_dropDownbackView.backgroundColor = [UIColor redColor];
    int i;
    int n = 0;
    //UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"listbg.png"]];
    for(i = 0; i<userCountInFile; i++)
    {
        UILabel *userTitleLabel = [[UILabel alloc]init];
        NSString *userNameStr = [[NSString alloc]init];
        userNameStr = [[app.moudle.userNameInFileList objectAtIndex:i]objectForKey:LOGIN_NAME];
        UIButton *usernamebutton = [UIButton buttonWithType:UIButtonTypeCustom];
        //[usernamebutton setTitle:userNameStr  forState:UIButtonTypeCustom];
        usernamebutton.frame = CGRectMake(0, 0+n, 223, everyListHight);
        [usernamebutton setImage:[UIImage imageNamed:@"listbg.png"]forState:UIControlStateNormal ];
        //usernamebutton.backgroundColor = color;
        
        userTitleLabel.frame = CGRectMake(8, 0, 215, everyListHight);
        userTitleLabel.text = userNameStr;
        userTitleLabel.textColor = [UIColor whiteColor];
        userTitleLabel.font = [UIFont systemFontOfSize:14];
        userTitleLabel.backgroundColor = [UIColor clearColor];
        
        //删除按键
        UIButton *delbutton = [UIButton buttonWithType:UIButtonTypeCustom];
        delbutton.frame = CGRectMake(183, 0, 40, everyListHight);
        [delbutton setImage:[UIImage imageNamed:@"del.png"]forState:UIControlStateNormal ];
        [delbutton setImage:[UIImage imageNamed:@"deled.png"]forState:UIControlStateSelected ];
        [delbutton addTarget:self action:@selector(deleteBtnPress:) forControlEvents:UIControlEventTouchUpInside];
       
        
        [usernamebutton addSubview:delbutton];
        [usernamebutton addSubview:userTitleLabel];
        [usernamebutton addTarget:self action:@selector(chooessUserName:) forControlEvents:UIControlEventTouchUpInside];
        [_dropDownListView addSubview:usernamebutton];
        n = n + everyListHight;
        usernamebutton.tag = i;
        delbutton.tag = i;
        //[userNameStr release];
    }
    //动画
    _dropDowAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
    if(presstimes%2 != 0)
    {
        _dropDowAnimation.fromValue = [NSNumber numberWithFloat:-listHight];
    }
    else 
    {
        _dropDownListView.frame = CGRectMake(0, -300, 223, listHight);
        
        _dropDowAnimation.fromValue = [NSNumber numberWithFloat:listHight];
    }
    _dropDowAnimation.toValue = [NSNumber numberWithFloat:0];
    //_dropDownListView.backgroundColor = [UIColor redColor];
    //x,y轴缩小到0.1,Z 轴不变
    //持续时间
    _dropDowAnimation.duration = 0.35;
    //重复次数
    _dropDowAnimation.repeatCount = 1;
    _dropDowAnimation.delegate = self;
    //设置_dropDownListView 的容量。
    [_dropDownListView setContentSize:CGSizeMake(185, listHight+20)];
    [_dropDownListView.layer addAnimation:_dropDowAnimation forKey:nil];
    [_dropDownbackView addSubview:_dropDownListView];
    
    //当第二次点的时候删除view。否则用户名就不能输入。
    if(presstimes%2 == 0)
    {
        [_dropDownbackView removeFromSuperview];
        _dropDownListView = nil;
        _dropDownbackView = nil;
    }
}
posted @ 2012-09-07 09:26  qingjoin  阅读(2885)  评论(0编辑  收藏  举报
  Sportica