juliodidier
juliodidier

Reputation: 81

Swift zoom with scrollview not centered

When setting (selected by taking a picture) the image of my imageview (which is inside a scrollview) is set but a little to the right and not centered as is supposed to be

Im not using storyboard, everything is made programmatically

//creating frames imgBorder.frame.size = CGSize(width: view.bounds.size.width * 0.7, height: view.bounds.size.height * 0.7) imgBorder.center.x = self.view.bounds.width * 0.5 imgBorder.center.y = self.view.bounds.height * 0.5 imgBorder.image = UIImage(named: "imageBorder") self.view.addSubview(imgBorder) self.view.bringSubviewToFront(imgBorder)

    scrollImg.delegate = self
    scrollImg.frame = CGRect(x: view.bounds.size.width * 0.5 -     imgBorder.frame.size.width/2, y: view.bounds.size.height * 0.5 - imgBorder.frame.size.height/2, width: imgBorder.bounds.size.width, height: imgBorder.bounds.size.height)
    scrollImg.minimumZoomScale = 1.0
    scrollImg.maximumZoomScale = 6.0

    self.view.addSubview(scrollImg)

    imgPicture.frame.size = scrollImg.frame.size
    imgPicture.center.x = scrollImg.center.x
    imgPicture.center.y = scrollImg.center.y

    scrollImg.addSubview(imgPicture)

First image shows when i take the picture (the problem in this post) Second shows the picture im taking Third shows that zoom is working fine with border limits image after taking a picture

picture taken

zoom working fine

Upvotes: 1

Views: 137

Answers (1)

juliodidier
juliodidier

Reputation: 81

I was able to fix the problem removing these lines of code:

imgPicture.center.x = scrollImg.center.x
imgPicture.center.y = scrollImg.center.y

Upvotes: 0

Related Questions