Group Group Group Group Group Group Group Group Group

When text is entered into textfield uipangesture effect becomes null

My swift code below creates 2 objects a imageview and a uitextfield. The imageview whichs is named pic is connected to a uipangestureReconginzier. When the user touches it moves around the view controller just like I want it to. However when the user touches the textfield and enters text. The pic is moved back to its defined constraint. I cant think of what is causing this.

 import UIKit

 class ViewController: UIViewController {
var g11 = UIPanGestureRecognizer()
var textEnter = UITextField()
var pic = UIImageView()

override func viewDidLoad() {
    // Do any additional setup after loading the view.
    g11 = UIPanGestureRecognizer(target: self, action: #selector(ViewController.g1Method))
        $0.translatesAutoresizingMaskIntoConstraints = false
        $0.backgroundColor = .systemBlue
        $0.isUserInteractionEnabled = true

    textEnter.backgroundColor = .brown

        pic.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant :0),
        pic.topAnchor.constraint(equalTo: view.topAnchor, constant : 0),

        pic.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 0.5, constant: 0),
        pic.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant : 0),

        textEnter.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant :0),
        textEnter.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant : 0),

        textEnter.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 0.3, constant: 0),
        textEnter.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant : 0),


@objc func g1Method(_ sender: UIPanGestureRecognizer){

    let tranistioon = sender.translation(in: self.view)
    sender.view!.center = CGPoint(x: sender.view!.center.x + tranistioon.x, y: sender.view!.center.y + tranistioon.y)
    sender.setTranslation(,in: self.view)    }


@timswift Do you still have issues with this?

thanks for checking on it

This topic was automatically closed after 166 days. New replies are no longer allowed.