代码之家  ›  专栏  ›  技术社区  ›  humblePilgrim

uiSegmentedControl自定义

  •  0
  • humblePilgrim  · 技术社区  · 15 年前

    我的一页上有一个uiSegmentedControl。当单击单击单击的段正下方的段时,我希望出现一个编辑框。我希望它是动画的(滑入或其他)

    这可能吗?最好的方法是什么?

    该死。我忘了提到所有这些动作都将发生在一个单元内,而不是一个简单的视图。

    2 回复  |  直到 13 年前
        1
  •  1
  •   Human-Behind    15 年前

    您可以尝试uiview动画。 首先设置你的编辑框(我猜是uitextview吗??)到X坐标320(因此不会显示)。 其次,当用户点击分段控件时,只需使用uiview动画翻译uitextview:

    [UIView beginAnimation:nil context:nil];
    [UIView setAnimationDuration: 1.0];
    CGAffineTransform trans = CGAffineTransformMakeTranslation(-320, 0);
    self.view.transform = trans;
    [UIView commitAnimations];
    

    希望它能帮助你。

        2
  •  0
  •   Human-Behind    15 年前

    好吧,那么我会尽量更精确一些,我猜你在使用接口生成器? 因此,必须将操作“链接”到uiSegmentedController,因此在类中编写此方法:

    -(IBAction) translateMyView
    {
      //If the first segment is selected do translation of the cellView
      if(yourSegmentedController.selectedSegmentIndex == 0)
      {
        [UIView beginAnimation:nil context:nil];
        [UIView setAnimationDuration: 1.0];
        //This will translate the view to its position from its position -320 px
        CGAffineTransform trans = CGAffineTransformMakeTranslation(-320, 0);
        //Replace self.view with the view you want to translate.
        self.view.transform = trans;
        [UIView commitAnimations];
      }
      else if(yourSegementedController.selectedSegmentIndex ==1)
      {
        //Do same thing that above but with another view
      }
    }
    

    因此,这是在SegmentedController中选择索引时发生的操作。 您需要做的是将此操作链接到接口生成器中的uiSegmentedController。

    希望能帮上忙;-)