Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将第N-1个按钮设置为其他按钮移除的位置_Ios_Objective C_Animation_Uibutton - Fatal编程技术网

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

Ios 将第N-1个按钮设置为其他按钮移除的位置,ios,objective-c,animation,uibutton,Ios,Objective C,Animation,Uibutton,比如说,我有N个按顺序排列的UIN按钮,一旦我选择了其中任何一个,它就会被删除。我想将第N-1个按钮设置为其他按钮被移除的位置。 请任何人向我推荐合适的方法。由于您没有提供代码,我将提供一个示例代码。请根据您的需要进行更改 如果有3个按钮,并且您正在点击第二个按钮,那么我们的方法应该是 ` [self lastbuttonOnToThisPosition:selectedbtn.tag] -(int)lastbutt0nToThisPosition:(int)pos

比如说,我有N个按顺序排列的UIN按钮,一旦我选择了其中任何一个,它就会被删除。我想将第N-1个按钮设置为其他按钮被移除的位置。
请任何人向我推荐合适的方法。

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

如果有3个按钮,并且您正在点击第二个按钮,那么我们的方法应该是

`

    [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;

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

-(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];

                     }];

}

请详细说明你到目前为止写了什么代码这是一个过多的评论。如果您想交流友好的私人谈话,请将其发送至Skype:)
[(UIButton*)[self.view viewWithTag:tagId] // assuming buttons are added to self.view