【问题标题】:Animate N-1th button to the position where other buttons removed将第 N-1 个按钮动画到移除其他按钮的位置
【发布时间】:2013-11-20 06:24:39
【问题描述】:
`

    [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 个按钮设置为其他按钮被移除的位置。 请任何人建议我合适的方法。

【问题讨论】:

  • 请说明你到目前为止写了什么代码

标签: ios objective-c animation uibutton


【解决方案1】:

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

如果有 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

【讨论】:

  • 这是过多的 cmets。如果你想交流友好的私人谈话,请把它带到 Skype 上:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-11
  • 1970-01-01
  • 2017-07-24
相关资源
最近更新 更多