单击提交按钮后如何在其正下方显示隐藏部分?
How to display a hidden part right underneath the submit button after it's clicked?
因此,我试图在单击提交按钮后使隐藏部分可见。更具体地说,这部分应该是一个 TableView,它将在用户 selections/entries 点击提交按钮之前显示。有办法吗?
请查看图片作为示例。
我尝试在 CocoaPods 中使用 ExpandableTableViewController 2.0。它使用 Tableview Controller 使 table 个单元格可扩展。但是,我不知道如何将它 implement/connect 放入我的 ViewController 中。如果你有更好的方法,请告诉我!
预先感谢您的帮助!
在您的 viewDidLoad()
中,隐藏 table,然后使用 self.Backview.center.y += 350
(或需要多少像素)向上移动您的 "Back" 和 "Next" 视图使其关闭)。
然后,一旦您收到一个条目,取消隐藏它,然后向下滑动 backView,使用
UIView.animateWithDuration(0.5, delay: 0.0,
options: [.CurveEaseOut], animations: {
self.backView.center.y -= 350
}, completion: nil)
这个动画提供了一个很好的滑动视图,并且缓入,给人一种幻灯片的错觉。这是我之前实现过的效果,效果很好。
祝你好运!
您还可以在代码中管理 UITableView
的高度限制以获得 expand/collapse 效果
这里是示例代码
@interface ViewController ()
{
BOOL toggleToshow;
}
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightConstraintTbl;
- (IBAction)btnSubmitClicked;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
toggleToshow = YES;
self.heightConstraintTbl.constant = 0;
}
- (IBAction)btnSubmitClicked {
[UIView animateWithDuration:1 animations:^{
self.heightConstraintTbl.constant = toggleToshow?285:0;
toggleToshow = !toggleToshow;
[self.view layoutIfNeeded]; // Make sure to Call this for getting nimation effect
}];
}
这里是swift版本
import UIKit
class AnimateViewController: UIViewController {
var toggleToshow = true;
@IBOutlet weak var heightConstraintTbl: NSLayoutConstraint!
@IBAction func btnSubmitClicked() {
UIView.animateWithDuration(1, animations: { () -> Void in
if self.toggleToshow{
self.heightConstraintTbl.constant = 285
}else{
self.heightConstraintTbl.constant = 0
}
self.toggleToshow = !self.toggleToshow
self.view.layoutIfNeeded(); // Make sure to Call this for getting nimation effect
})
}
override func viewDidLoad() {
super.viewDidLoad()
toggleToshow = true;
self.heightConstraintTbl.constant = 0;
// Do any additional setup after loading the view.
}
编码愉快...
查看link约束
的屏幕截图
因此,我试图在单击提交按钮后使隐藏部分可见。更具体地说,这部分应该是一个 TableView,它将在用户 selections/entries 点击提交按钮之前显示。有办法吗?
请查看图片作为示例。
我尝试在 CocoaPods 中使用 ExpandableTableViewController 2.0。它使用 Tableview Controller 使 table 个单元格可扩展。但是,我不知道如何将它 implement/connect 放入我的 ViewController 中。如果你有更好的方法,请告诉我!
预先感谢您的帮助!
在您的 viewDidLoad()
中,隐藏 table,然后使用 self.Backview.center.y += 350
(或需要多少像素)向上移动您的 "Back" 和 "Next" 视图使其关闭)。
然后,一旦您收到一个条目,取消隐藏它,然后向下滑动 backView,使用
UIView.animateWithDuration(0.5, delay: 0.0,
options: [.CurveEaseOut], animations: {
self.backView.center.y -= 350
}, completion: nil)
这个动画提供了一个很好的滑动视图,并且缓入,给人一种幻灯片的错觉。这是我之前实现过的效果,效果很好。
祝你好运!
您还可以在代码中管理 UITableView
的高度限制以获得 expand/collapse 效果
这里是示例代码
@interface ViewController ()
{
BOOL toggleToshow;
}
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightConstraintTbl;
- (IBAction)btnSubmitClicked;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
toggleToshow = YES;
self.heightConstraintTbl.constant = 0;
}
- (IBAction)btnSubmitClicked {
[UIView animateWithDuration:1 animations:^{
self.heightConstraintTbl.constant = toggleToshow?285:0;
toggleToshow = !toggleToshow;
[self.view layoutIfNeeded]; // Make sure to Call this for getting nimation effect
}];
}
这里是swift版本
import UIKit
class AnimateViewController: UIViewController {
var toggleToshow = true;
@IBOutlet weak var heightConstraintTbl: NSLayoutConstraint!
@IBAction func btnSubmitClicked() {
UIView.animateWithDuration(1, animations: { () -> Void in
if self.toggleToshow{
self.heightConstraintTbl.constant = 285
}else{
self.heightConstraintTbl.constant = 0
}
self.toggleToshow = !self.toggleToshow
self.view.layoutIfNeeded(); // Make sure to Call this for getting nimation effect
})
}
override func viewDidLoad() {
super.viewDidLoad()
toggleToshow = true;
self.heightConstraintTbl.constant = 0;
// Do any additional setup after loading the view.
}
编码愉快...
查看link约束
的屏幕截图