简体   繁体   中英

How to Change image on UILongPressGestureRecognizer?

I am working on SMS application for Iphone .. And now i want to change image of my chat bubble on longpress ( like while i copy the contant )..

i have this code ..

if (longPressRecognizer.state == UIGestureRecognizerStateBegan) 
    {


        [self becomeFirstResponder];

        //NSIndexPath *pressedIndexPath = [tblOutgoingMessagesRecords indexPathForRowAtPoint:[longPressRecognizer locationInView:tblOutgoingMessagesRecords]];

        NSIndexPath *pressedIndexPath = [tblOutgoingMessagesRecords indexPathForCell:(UITableViewCell *)longPressRecognizer.view];
        if (pressedIndexPath && (pressedIndexPath.row != NSNotFound) && (pressedIndexPath.section != NSNotFound)) 
        {
            [self becomeFirstResponder];
            NSLog(@" Presssed on Copy ");

I just want to change my Chat bubble color to blue while i lonpress it for copy .. As like in iphone default has done i want to do same ... Can any one help me ...

It seems you have to check if the state is UIGestureRecognizerStateRecognized to change the Chat bubble's color,

if (longPressRecognizer.state == UIGestureRecognizerStateRecognized) {

    // Change Chat bubble's color to blue
}

check color to red when long press gesture begin condition

if (longPressRecognizer.state == UIGestureRecognizerStateBegan) 
{


    [self becomeFirstResponder];
   // change image from  here
    //NSIndexPath *pressedIndexPath = [tblOutgoingMessagesRecords indexPathForRowAtPoint:[longPressRecognizer locationInView:tblOutgoingMessagesRecords]];

    NSIndexPath *pressedIndexPath = [tblOutgoingMessagesRecords indexPathForCell:(UITableViewCell *)longPressRecognizer.view];
    if (pressedIndexPath && (pressedIndexPath.row != NSNotFound) && (pressedIndexPath.section != NSNotFound)) 
    {
        [self becomeFirstResponder];
        NSLog(@" Presssed on Copy ");
  }
}
else  if (longPressRecognizer.state == UIGestureRecognizerStateChanged)
 {

    //load original  image here...

   } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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