1

Мне нужна помощь. Сегодня я работаю над пользовательской ячейкой таблицы, где ячейка содержит UIImageView. В ImageView я хочу реализовать длинный жест. Я реализую код для этого, который ниже. Но я делаю что-то не так в своем коде. В этом представлении размер изменяется один раз при длительном нажатии, но я хочу, чтобы после нескольких секунд его можно было удалить и вернуться в ячейку просмотра таблицы. Может ли кто-нибудь предложить мне ????Длинный жест нажатия на изображение в пользовательской ячейке таблицы.

Update:

long gesture Image

Вот код!

- (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]; 
} 
+0

Показать результирующий вывод и код, который вы пишете для него. –

+0

clipSubviews можно проверить на CustomCell! Попытайтесь отключить это либо cellForRowAtIndexPath(), либо в Interface Builder, если используете ячейки прототипа! – Ariel

+0

Attache images plz –

ответ

0
[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 
+0

Я уже пытаюсь это !! –

+0

Включено clipViews в пользовательской ячейке? – Ariel

+0

Добавьте длинный прессовый код в вопрос. –

1
 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; 
} 
+0

Вы пробовали этот код? @simerkaur –

+0

это работает? @simerkaur –

+0

не могли бы вы отправить сообщение об ошибке? @simerkaur –

0

Попробуйте: Клетка SuperView из ImageView так на размер его изменения не кросс клетки рама добавьте его в mainView после изменения размера.

+0

сейчас! мое приложение разбито –

+0

Просьба предоставить сообщение об ошибке – jagdish

+0

Это происходит, когда класс не отвечает на метод. перед вызовом проверки, если ([ActivityFeedViewController instanceRespondToSelector: @selector (celllongpressed:)]) { /} – jagdish

Смежные вопросы