Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

395
Visualizações
Cambiar el tamaño de la fuente y el marco con pinchGesture cuando textView isScrollEnabled = false

He usado pinchGesture para acercar y alejar textView usando el siguiente código.

añadido pinchGesture a textView

 let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(self.handlePinch)) pinchGesture.delegate = self view.addGestureRecognizer(pinchGesture)

delegado

 @IBAction func handlePinch(recognizer:UIPinchGestureRecognizer) { if let view = recognizer.view as? UITextView { view.transform = view.transform.scaledBy(x: recognizer.scale, y: recognizer.scale) recognizer.scale = 1 } }

Resultado

ingrese la descripción de la imagen aquíingrese la descripción de la imagen aquí

Aquí está la posible solución que he aplicado pero aún no puedo encontrar la solución perfecta.

 @IBAction func handlePinch(recognizer:UIPinchGestureRecognizer) { if let textView = recognizer.view as? UITextView { let font = textView.font! var pointSize = font.pointSize let fontName = font.fontName pointSize = ((recognizer.velocity > 0) ? 1 : -1) * 1 + pointSize; if (pointSize < 13) { pointSize = 13 } if (pointSize > 100) { pointSize = 100 } textView.font = UIFont(name: fontName, size: pointSize) } }

Resultado

ingrese la descripción de la imagen aquí

Usando la solución anterior, puedo aumentar el tamaño de la fuente con éxito, pero el marco textView no se actualiza, por lo que el texto se corta porque el marco textView es más pequeño.

Resultado Esperado

La fuente aumentará y también el marco se actualizará, por lo que se verá como un simple acercamiento y alejamiento, pero sin desenfoque.

Buscando la mejor solución posible para aumentar el tamaño de la fuente con un marco como lo están haciendo Instagram y Snapchat .

Gracias.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Aquí está el código para cambiar el tamaño de la fuente junto con el marco al pellizcar acercar/alejar usando UITextView e isScrollEnabled = false

 @objc func pinchRecoginze(_ pinchGesture: UIPinchGestureRecognizer) { guard recognizer.view != nil, let view = recognizer.view else {return} if view is UITextView { let textView = view as! UITextView if recognizer.state == .began { let font = textView.font let pointSize = font!.pointSize recognizer.scale = pointSize * 0.1 } if 1 <= recognizer.scale && recognizer.scale <= 10 { textView.font = UIFont(name: textView.font!.fontName, size: recognizer.scale * 10) let textViewSiSize = textView.intrinsicContentSize textView.bounds.size = textViewSiSize } } }

Tamaño de fuente más pequeño

Pellizcar zoom para tamaño de fuente más grande

Respuesta actualizada a compatible con UITextView

over 4 years ago · Santiago Trujillo Relatório

0

Aquí está el cambio de tamaño de fuente y marco con pinchGesture cuando textView isScrollEnabled = false .

 @IBAction func handlePinch(recognizer:UIPinchGestureRecognizer) { if let view = recognizer.view { if view is UITextView { let textView = view as! UITextView if textView.font!.pointSize * recognizer.scale < 90 { let font = UIFont(name: textView.font!.fontName, size: textView.font!.pointSize * recognizer.scale) textView.font = font let sizeToFit = textView.sizeThatFits(CGSize(width: UIScreen.main.bounds.size.width, height:CGFloat.greatestFiniteMagnitude)) textView.bounds.size = CGSize(width: textView.intrinsicContentSize.width, height: sizeToFit.height) } else { let sizeToFit = textView.sizeThatFits(CGSize(width: UIScreen.main.bounds.size.width, height:CGFloat.greatestFiniteMagnitude)) textView.bounds.size = CGSize(width: textView.intrinsicContentSize.width, height: sizeToFit.height) } textView.setNeedsDisplay() } else { view.transform = view.transform.scaledBy(x: recognizer.scale, y: recognizer.scale) } recognizer.scale = 1 } }
over 4 years ago · Santiago Trujillo Relatório

0

¿Qué sucede si intenta habilitar el desplazamiento al comienzo de su método handlePinch y lo deshabilita nuevamente al final de pellizcar?:

 @IBAction func handlePinch(recognizer:UIPinchGestureRecognizer) { if let textView = recognizer.view as? UITextView { textView.isScrollingEnabled = true let font = textView.font! var pointSize = font.pointSize let fontName = font.fontName pointSize = ((recognizer.velocity > 0) ? 1 : -1) * 1 + pointSize; if (pointSize < 13) { pointSize = 13 } if (pointSize > 100) { pointSize = 100 } textView.font = UIFont(name: fontName, size: pointSize) let width = view.frame.size.width textView.frame.size = textView.sizeThatFits(CGSize(width: width, height: CGFloat.greatestFiniteMagnitude)) textView.isScrollingEnabled = false } }
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda