【问题标题】:How to do this effect这个效果怎么做
【发布时间】:2012-07-09 11:38:52
【问题描述】:

我想知道这个效果怎么做:

当用户点击初始屏幕上的加号时(见第一张截图),列表将下拉,加号变为减号(见第二张截图)。


(来源:store.qq.com)

【问题讨论】:

  • 您链接的图片好像被屏蔽了。
  • 我无法查看第一张图片;你能把它上传到别处吗?
  • 第二张图片加载不出来...
  • 复制和粘贴伙计们,@user1506299 我不清楚你在问什么。单击后是否要更改按钮图像?还是要将底部视图移出屏幕?
  • 我怀疑他想知道如何使用标题旁边显示的 +/- 符号来展开/折叠文本。

标签: ios show-hide


【解决方案1】:

你必须自己写。例如,这是一个超级简单的示例,向您展示如何隐藏和显示内容。我没有使用图形 +/- 按钮(而是一个简单的文本按钮),但希望这可以为您提供足够的线索,让您自己正确地执行此操作。这只是演示了显示文本面板的动画(您可以在此面板上放置图形或其他任何内容)。

有很多方法可以做到这一点,但这过于简单,显然我没有花任何时间在美学上,但希望它向您展示了一些您可以使用的技术。我认为关键技巧是将要显示的内容放在主视图上的 UIView 上,将其高度设为零,然后对要扩展的框架的更改进行动画处理。您还可以移动按钮、更改用于按钮操作的 UIImage 等,但您明白了。

//  SlideInViewController.m

#import "SlideInViewController.h"

@interface SlideInViewController ()
{
    UIView *_hiddenPanel;
    UIButton *_hideShowButton;
    BOOL _panelHidden;
}
@end

@implementation SlideInViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // initialize the flag

    _panelHidden = YES;

    // create the panel that will be hidden initially (height of zero), but will be revealed when you click on the button

    _hiddenPanel = [[UIView alloc] initWithFrame:CGRectMake(0.0, 300.0, self.view.frame.size.width, 0.0)];
    _hiddenPanel.clipsToBounds = YES;
    [self.view addSubview:_hiddenPanel];

    // add the button

    _hideShowButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    _hideShowButton.frame = CGRectMake(40.0, 260.0, 40.0, 40.0);
    [_hideShowButton setTitle:@"+" forState:UIControlStateNormal];
    [_hideShowButton addTarget:self action:@selector(hideShowPanel:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_hideShowButton];

    // now put whatever you want on this hidden panel.

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, 200.0)];
    label.lineBreakMode = UILineBreakModeWordWrap;
    label.numberOfLines = 0;
    label.text = @"This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. This is a very long label. ";
    [_hiddenPanel addSubview:label];

    // Do any additional setup after loading the view.
}

- (IBAction)hideShowPanel:(id)sender
{
    if (_panelHidden)
    {
        // if the panel was already hidden, let's reveal it (and move/adjust the button accordingly)

        [UIView animateWithDuration:1.0 animations:^{
            _hideShowButton.frame = CGRectMake(40.0, 60.0, 40.0, 40.0);
            [_hideShowButton setTitle:@"-" forState:UIControlStateNormal];

            _hiddenPanel.frame = CGRectMake(0.0, 100.0, self.view.frame.size.width, 200.0);
        }];
    }
    else
    {
        // if the panel was already shown, so now let's hide it again (and move/adjust the button accordingly)
        [UIView animateWithDuration:1.0 animations:^{
            _hideShowButton.frame = CGRectMake(40.0, 260.0, 40.0, 40.0);
            [_hideShowButton setTitle:@"+" forState:UIControlStateNormal];

            _hiddenPanel.frame = CGRectMake(0.0, 300.0, self.view.frame.size.width, 0.0);
        }];
    }

    _panelHidden = !_panelHidden;
}

@end

【讨论】:

  • 想了很多。我会试试这个。
猜你喜欢
  • 2014-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-17
相关资源
最近更新 更多