如何在iOS中不使用tableview创建可扩展视图

时间:2014-04-11 07:22:10

标签: ios objective-c uitableview

我是iPhone开发的初学者,无法创建可扩展的视图。就像点击tableview行一样,它们会扩展到更多行。我想用一些标题创建两个标题,当用户先点击然后他们的详细视图打开时,在agin点击详细视图上隐藏动画。在第二个标题中相同。

这两个标题之间应该有一些区别。 请帮我 。我在此链接的图片中找到了有关我的要求的链接,但无法实现。

1 个答案:

答案 0 :(得分:0)

你可以有一个UIView,其高度为0,然后在点击你的按钮时展开它:

UIView *expandableView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,0)];
expandableView.backgroundColor = [UIColor redColor];
expandableView.alpha = 0;

然后当你点击你的按钮时你会做一个动画

[self.view addSubview:expandableView];
CGRect newFrame = expandableView.frame;
newFrame.size.height = 100;

//If this is the first view you would have to move the second header below 
CGRect newHeaderFrame = header2.frame;
newHeaderFrame.origin.y += expandableView.frame.size.height; 

[UIView animateWithDuration:0.3 animations:^{
    expandableView.frame = newFrame;
    expandableView.alpha = 1;
    header2.frame = newHeaderFrame;
}];

当你想缩小它时:

CGRect newFrame = expandableView.frame;
newFrame.size.height = 0;

//If this is the first view you would have to move back to header 2
CGRect newHeaderFrame = header2.frame;
newHeaderFrame.origin.y -= newFrame.size.height; 

[UIView animateWithDuration:0.3 animations:^{
    expandableView.frame = newFrame;
    expandableView.alpha = 0;
    header2.frame = newHeaderFrame;
} completion:^{
    [expandableView removeFromSuperview];
}];