1

I am creating Custom GIF Keyboard in iOS8 using app extension. I was created layout of my custom keyboard. I was implement LongPress Gesture for selecting GIF Image but its not work. so what can i do for this or any suggestion regarding to this?


- (void)textWillChange:(id<UITextInput>)textInput {
    [self.textDocumentProxy insertText:@"Hi"];
}

I also tried with UITextInputDelegate mentioned above. This method is also deals with only text append. But My concern is to load gif or png image in input area.

mital solanki
  • 2,394
  • 1
  • 15
  • 24

3 Answers3

3

I have done with long press gesture and make a method for touch handler.

-(void)tapped:(id)sender
{
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    UIImage *image = [UIImage imageNamed:@"img_temp.gif"];
    NSData *imgData = UIImagePNGRepresentation(image);
    [pasteboard setData:imgData forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]];
}

I also given become first responder aswell.

-(BOOL)canBecomeFirstResponder
{
    return YES;
}

I can copy text in pasteboard, but I can't copy .gif or .png image.

RaviM
  • 62
  • 14
2

What Popkey, for example, are doing is copy the clicked GIF to the pasteboard.

The user then needs to long click their rich text field and paste the content into their iMessage for example.

nurnachman
  • 4,468
  • 2
  • 37
  • 40
0

You couldn't load a gif directly in the input area. To do that you have to copy the gif to the pasteboard and then paste the gif in the input area.

To copy the gif into the pasteboard you need to convert it into the NSData.

Here is the demo code in Swift 3.0.

let pb = UIPasteboard.general
let data = NSData(contentsOfURL: url)
 if data != nil
  {
     self.pb.setData(data!, forPasteboardType: kUTTypeGIF as String)
  }
Ramakrishna
  • 712
  • 8
  • 26