How to scale MSStickerView to the size of MSSticker?

434 views Asked by At

My iMessage Extension is currently generating images based on a text input and presenting them to the user as Stickers in an MSStickerView. The user can manipulate the size of the Sticker via a slider bar. To do this, I am scaling the generated image, adding the sticker and then resizing the MSStickerView with sizeToFit().

The problem is that the StickerView and Sticker displayed only decrease in size, but increase only when the Extension view is switched (large to small or vise-versa). I know that the view uses cached images which is why I am saving my images with names based on the text input and size. However, I am expecting some other cache system is used, which prevents me from using larger images.

Is there a way for me to programmatically trigger a reload similar to the one occurring when switching views or to just resize the MSStickerView manually?

func createSticker(_ sender: Any) {
    
    deleteStoredImage(fileName: lastFileName)
    
    // generate a Sticker from the text in the UITextField
    var inputText = " "
    inputText = textInput.text!
    if(inputText.characters.count == 0){
        inputText = " "
    }
    
    var stickerImage = inputText.image()
    stickerImage = resizeImage(image: stickerImage!, targetHeight: CGFloat(sizeSlider.value*150))
    
    // create a unique filename from text+size
    let filename = inputText+String(sizeSlider.value)+"Sticker.png"
    lastFileName = filename
    print("attempting to write file: " + filename)
    storeImage(img: stickerImage!, fileName: filename)
    
    // load the recently stored image into an MSSticker
    var textSticker: MSSticker!
    
    let url = getDocumentsDirectory().appendingPathComponent(filename)
    do {
        textSticker = try MSSticker(contentsOfFileURL: url, localizedDescription: "")
    } catch {
        print(error)
    }
    
    // display the sticker in the stickerView and resize/ move it accordingly
    stickerView.sticker = textSticker
    stickerView.sizeToFit()
    stickerView.center = CGPoint(x: stickerContainer.center.x, y: stickerContainer.center.y*0.6)

An image of the UI:

UI

0

There are 0 answers