点击CollectionViewCell / tableView
2022-02-14 本文已影响0人
不要虚度美好的时光
一、CollectionViewCell 的放大与缩小:
1. 点击CollectionViewCell 放大与缩小:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
// 取消高亮
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
HomeCollectionViewCell *cell = (HomeCollectionViewCell *)[self.notesCollectionView cellForItemAtIndexPath:indexPath];// cellForRowAtIndexPath:indexPath];
if (cell) {
[UIView animateWithDuration:0.1 animations:^{
cell.transform = CGAffineTransformMakeScale(1.2, 1.2);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.1 animations:^{
cell.transform = CGAffineTransformMakeScale(1.0, 1.0);
} completion:^(BOOL finished) {
//这里实现点击cell后要实现的内容
NSLog(@"点击Cell后,放大缩小Cell");
}];
}];
}
- 当Cell上层被其它控件覆盖时,如何穿透上层控件,响应点击事件
#import "HomeCollectionViewCell.h"
@implementation HomeCollectionViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
UIView *hitView = [super hitTest:point withEvent:event];
if(hitView == self.hanziView_View){
return self;
}
return hitView;
}
@end
二、TableViewCell 的放大与缩小:
1. 带动画的放大与缩小:
GlossaryTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIView *tempMoveCell = [cell snapshotViewAfterScreenUpdates:NO];
tempMoveCell.frame = cell.frame;
[tableView addSubview:tempMoveCell];
[UIView animateWithDuration:0.3 animations:^{
tempMoveCell.transform = CGAffineTransformMakeScale(1.05, 1.05);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3 animations:^{
tempMoveCell.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
[tempMoveCell removeFromSuperview];
// [self.navigationController pushViewController:controller animated:YES];
}];
}];
2. tableViewCell 放大与缩小
CGRect frame = cell.frame;
frame.origin.y -= 20;
frame.size.height += 40;
cell.frame = frame;
[_tableView beginUpdates];
[_tableView endUpdates];