简体   繁体   English

iOS 5子视图在TableView单元格中的两个视图之间翻转

[英]ios 5 subview flip between two view in tableview cell

I have tableview which contains custom cell. 我有包含自定义单元格的tableview。 Each cell has view that I want to flip when user click on that row. 用户单击该行时,每个单元格都有要翻转的视图。 I successfully made it work for this one. 我成功地使其适用于此。 But the point I struggle with is when user clicks on other row, I want to flip back to original view for previous cell and flip currently clicked row. 但是我要解决的问题是当用户单击另一行时,我想返回到上一个单元格的原始视图并翻转当前单击的行。

here is some code 这是一些代码

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

CustomCell *selectedCell = 
        (CustomCell *)[self.AlbumViewTable cellForRowAtIndexPath:self.current_index];
//if other row is already flipped then make it back to original state.
if(otherRowIsFlipped){
    selectedCell.defaultImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"defaultIndecator.jpg"]];
    selectedCell.defaultImage = CGRectMake(0, 0, 43, 43);
    [self flipView:selectedCell.flipViewContainer From:selectedCell.activity To:selectedCell.defaultImage];
}

CustomCell * new_row = 
        (CustomCell *)[self.AlbumViewTable cellForRowAtIndexPath:indexPath];


new_row.activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
new_row.activity.frame = CGRectMake(0, 0, 43, 43);
[new_row.activity startAnimating];

 //this method is merely called UIView subroutine to flip between two view 
[self flipView:new_row.flipViewContainer From:new_row.defaultImage To:new_row.activity];

[self.AlbumViewTable deselectRowAtIndexPath:indexPath animated:YES];
}

I was able to flip back previously selected row and flip currently selected row, yet I found weird thing that when I scroll down tableview and flip view appeared on a row which has never been selected. 我能够向后翻转先前选择的行并翻转当前选择的行,但是我发现当我向下滚动tableview和flip view时,奇怪的事情出现在从未被选择的行上。

I tried to make properties in CustomCell class and attempted to flip but no luck too. 我试图在CustomCell类中创建属性,并尝试翻转但也没有运气。 I'm not sure this approach is correct but it seems to work unless I scroll down to load other rows. 我不确定这种方法是否正确,但除非向下滚动以加载其他行,否则它似乎可以正常工作。

I'd appreciate for any advices. 如有任何建议,我将不胜感激。 Thanks 谢谢

You should make a custom TableViewCell with such view structure 您应该使用这种视图结构制作一个自定义TableViewCell

-CELL
--CONTENT_VIEW
---1st_side
---2nd_side

and the code is 和代码是

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.7f];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:containerView cache:NO];
  [firstView removeFromSuperview];
  [containerView addSubview:secondView];
[UIView commitAnimations];

and the same for back method 和后面的方法一样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM