我有一个带有隐藏属性的tableview。我想用动画取消隐藏,以便它可以从下到上滑动?请提出任何建议。
-(IBAction) hideTable : (id) sender;
{
if(self.tb.hidden==true)
{
self.tb.alpha=1;
[self.tb setHidden:NO];
}
else{
[self.tb setHidden:YES];
}
}
答案 0 :(得分:4)
-(IBAction) hideTable : (id) sender{
if (self.sessionView.hidden == YES) {
// Currently NOT Visible. Show it now
// First unhide it
yourTableView.hidden = NO;
[UIView animateWithDuration:0.5f
animations:^{
// Get the Existing table View frame
CGRect hiddenFrame = yourTableView.frame;
// Reset it to 0 or your own value
hiddenFrame.origin.y = 0;
// Set the new frame
yourTableView.frame = hiddenFrame;
} completion:^(BOOL finished) {
NSLog(@"Shown");
}];
}
else{
// Currently Visible. Hide it Now
[UIView animateWithDuration:0.5f
animations:^{
// Get the Existing table View frame
CGRect hiddenFrame = yourTableView.frame;
// Under the superview height
hiddenFrame.origin.y = yourTableView.superview.frame.size.height;
// Set the new frame
yourTableView.frame = hiddenFrame;
} completion:^(BOOL finished) {
yourTableView.hidden = YES;
NSLog(@"Hidden");
}];
}
}
答案 1 :(得分:2)
试试这个
CGRect frame = self.tb.frame;
if (self.tb.hidden) {
CGRect temp_frame = frame;
frame.size.height = 1;
self.tb.frame = temp_frame;
self.tb.hidden = NO;
[UIView animateWithDuration:0.3
animations:^{
self.tb.frame = frame;
} completion:^(BOOL finished) {
}];
}
else
{
[UIView animateWithDuration:0.3
animations:^{
CGRect temp_frame = frame;
frame.size.height = 1;
self.tb.frame = temp_frame;
} completion:^(BOOL finished) {
self.tb.hidden = YES;
}];
}
答案 2 :(得分:0)
试试这个
-(IBAction) hideTable : (id) sender;
{
if(self.tb.hidden==true)
{
self.tb.alpha=1;
[self.tb setHidden:NO];
[UIView animateWithDuration:.25
animations:^{
self.tb.frame = CGRectMake(0,50,320,400); // your req frame
}
];
}
else
{
[UIView animateWithDuration:0.35
animations:^{
self.tb.frame = CGRectMake(0, self.view.frame.size.height+10, 320,400); // y point of yor tableview is more than view bounds so it goes down
}
completion:^(BOOL finished){
[self.tb setHidden:YES];
}
];
}
}
答案 3 :(得分:0)
You can use the below methods:
1. (void)showDropDownTable:- To show tableview with top to bottom animation.
2. (void)hideDropdownTable:- To hide tableview with bottom to top animation.
- (IBAction)btnDropDownClicked:(id)sender
{
if (checkShowHideTableView == TRUE)
{
[self hideTableView];
}
if (self.tblDropDown.hidden)
{
[self showDropDownTable];
}
else
{
[self hideDropdownTable];
}
}
- (void)showDropDownTable
{
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationCurveEaseOut animations: ^{
_tblDropDown.frame = CGRectMake(self.tblDropDown.frame.origin.x, self.tblDropDown.frame.origin.y, self.tblDropDown.frame.size.width, kDropdownTableHeight);
self.tblDropDown.hidden = FALSE;
} completion: ^(BOOL finished) {
}];
}
- (void)hideDropdownTable
{
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationCurveEaseOut animations: ^{
_tblDropDown.frame = CGRectMake(self.tblDropDown.frame.origin.x, self.tblDropDown.frame.origin.y, self.tblDropDown.frame.size.width, 0);
} completion: ^(BOOL finished) {
self.tblDropDown.hidden = TRUE;
}];
}
Hope this can help you.
答案 4 :(得分:-1)
尝试以下
[self.tb beginUpdates];
[UIView animateWithDuration:0.5
delay:0.1
options:(UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction)
animations:^{
if(self.tb.isHidden)
{
self.tb.alpha=1;
[self.tb setHidden:NO];
}
else
{
self.tb.alpha=0;
[self.tb setHidden:YES];
}
}
completion:^(BOOL finished) {
}];
[self.tb endUpdates];