将N-1个按钮设置为移除其他按钮的位置

时间:2013-11-20 06:24:40

标签: ios objective-c animation uibutton

`

    [self lastbuttonOnToThisPosition:selectedbtn.tag]

    -(int)lastbutt0nToThisPosition:(int)pos
    {
        int p=[array count]-1;
        if((pos) == ([array count]-1))
            return 0;
        for(p=[array count]-1;p>=0;--p)
        {
            UIButton *btn=(UIButton*)[self.view viewWithTag:p];
            if(![btn isSelected])
            {
                UIButton *Remove=(UIButton*)[self.view viewWithTag:pos];
                [Remove   removeFromSuperview];
                [btn     setTag:pos];

                [array replaceObjectAtIndex:pos withObject:[array objectAtIndex:p]];
                [array removeObjectAtIndex:p];
                return p;
            }
        }
        return p;

}`

我已经说过,例如N UIButtons按顺序排列,一旦我选择其中的任何一个,它就会被删除。我想将N-1个按钮设置为移除其他按钮的位置。 请有人建议我使用合适的方法。

1 个答案:

答案 0 :(得分:2)

由于你没有提供你的代码,我提供了一个示例代码。请根据您的需要进行更改。

如果有3个按钮,如果你点击第二个按钮,那么我们的方法应该是

-(IBAction)tappedBtn2:(id)sender
{
    [UIView animateWithDuration:0.33f
                          delay:0.0f
                        options:UIViewAnimationOptionShowHideTransitionViews
                     animations:^{
                         [btn2 removeFromSuperview];
                         [btn3 removeFromSuperview];
                     }
                     completion:^(BOOL finished){
                         [UIView animateWithDuration:0.33f
                                               delay:0.0f
                                             options:UIViewAnimationOptionCurveEaseInOut
                                          animations:^{
                                              [btn1 setFrame:CGRectMake(btn2.frame.origin.x, btn2.frame.origin.y , btn1.frame.size.width, btn1.frame.size.height)];
                                          }
                                          completion:nil];

                     }];

}

如果您使用for循环,则使用以下代码获取具有特定标记的uibutton以进行删除和动画

[(UIButton*)[self.view viewWithTag:tagId] // assuming buttons are added to self.view
相关问题