在tableview自定义单元格中的图像上长按手势
我需要一些帮助。 今天,我正在研究表视图自定义单元格,其中单元格包含UIImageView
。 在ImageView上,我想实现长手势。 我实现了下面给出的代码..但是我在我的代码中做错了。在这个视图中长按一次resize但我希望在几秒后它可以删除并返回表视图单元格可以有人建议我????
更新:
这是代码!
- (void)celllongpressed:(UILongPressGestureRecognizer *)gesture { if (gesture.state == UIGestureRecognizerStateBegan) { cell = (ActivityFeedCell *)[gesture view]; } if (gesture.state == UIGestureRecognizerStateChanged) { cell = (ActivityFeedCell *)[gesture view]; logGes_view=[[UIView alloc]initWithFrame:CGRectMake(5, 0,self.view.frame.size.width-10,self.view.frame.size.height)]; image=[[UIImageView alloc]initWithFrame:CGRectMake(0, 80,self.view.frame.size.width, self.view.frame.size.height-80)]; image.image=cell.updated_imgView.image; UILabel *name_label=[[UILabel alloc]initWithFrame:CGRectMake(10, 15, 150, 30)]; //city_label.backgroundColor=[UIColor yellowColor]; name_label.text=lgGesNamelbl; UILabel *city_label=[[UILabel alloc]initWithFrame:CGRectMake(10, 50, 180, 30)]; //city_label.backgroundColor=[UIColor yellowColor]; city_label.text=lgGesCitylbl; [logGes_view addSubview:city_label]; [logGes_view addSubview:name_label]; [logGes_view addSubview:image]; logGes_view.backgroundColor=[UIColor whiteColor]; [self.view addSubview:logGes_view]; } if (gesture.state == UIGestureRecognizerStateEnded) { // cell = (ActivityFeedCell *)[gesture view]; [logGes_view removeFromSuperview]; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UILongPressGestureRecognizer *gesture1 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(celllongpressed:)]; [gesture1 setDelegate:self]; [gesture1 setMinimumPressDuration:1.0]; [ cell setUserInteractionEnabled:YES]; [cell addGestureRecognizer:gesture1]; }
UILongPressGestureRecognizer *reconizer=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPress:)]; [reconizer setMinimumPressDuration:1.0]; [cell addGestureRecognizer:reconizer]; -(void)handleLongPress:(UILongPressGestureRecognizer*)reconizer { if (gesture.state == UIGestureRecognizerStateBegan) { UITableViewCell *cell = (UITableViewCell *)[gesture view]; NSIndexPath *indexPath = [tableview indexPathForCell:cell]; NSString *s = [NSString stringWithFormat: @"row=%1ld",(long)indexPath.row]; [self setTitle: s]; } if (gesture.state == UIGestureRecognizerStateChanged) { cell = (UITableViewCell *)[gesture view]; cell.updated_imgView.frame=CGRectMake(0, 0, tableview.frame.size.width, tableview.frame.size.height); } if (gesture.state == UIGestureRecognizerStateEnded) { cell = (UITableViewCell *)[gesture view]; cell.updated_imgView.frame=CGRectMake(0, 0, 100, 100); }
}
-(BOOL)canBecomeFirstResponder { return YES; }
[cell addGestureRecognizer:gesture1]
用以下线代替
[ cell.yourimageview setUserInteractionEnabled:YES]; // This enable user interaction on the image view. Required!! [cell.yourimageview addGestureRecognizer:gesture1]; //yourimageview is your image outlet
尝试一下:Cell是imageView的超级视图,所以大小改变它不会跨越单元格框架在resize后将其添加到mainView。
- 如何检测“LocallAPStore” – 新的iapcookies
- MVVMCROSS Ios绑定ShowViewModel
- 为什么我得到延迟加载NSBundle MobileCoreServices.framework?
- iOS Swift MapKit使用户可以拖动注释吗?
- 如何重新加载UIViewController
- 在NSFetchedResultsController的空表上定制单元格
- 如何将UiSearchBar的背景颜色更改为黑色-SWIFT
- Swift 2 – performBatchUpdates – 在UICollectionView框架内部可视化的时候,一个接一个地animation单元格
- 你如何做一个背景图像缩放到迅速的屏幕大小?