【发布时间】:2016-07-27 10:51:57
【问题描述】:
我需要一些帮助。今天,我正在处理表格视图自定义单元格,其中单元格包含UIImageView。在 ImageView 上,我想实现长手势。我为此实现了下面给出的代码..但我在我的代码中做错了。在这个视图中长按一次调整大小但我希望在几秒钟后它可以被删除并返回表格视图单元格
谁能推荐我????
更新:
这是代码!
- (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];
}
【问题讨论】:
-
显示结果输出和您为此编写的代码。
-
clipSubviews 可以在 CustomCell 上检查!如果使用原型单元,请尝试禁用 cellForRowAtIndexPath() 或 Interface Builder!
-
请附上图片
-
@simerkaur 您不应在评论部分发布代码和图像。请在问题中发布以获取更多详细信息!
-
在手势方法中 if (gesture.state == UIGestureRecognizerStateBegan) { UITableViewCell *cell = (UITableViewCell *)[gesture view]; } 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(30, 0, 300, 300); }
标签: ios objective-c uitableview uigesturerecognizer uilongpressgesturerecogni