Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the default aspect ratio setting #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bratyslav
Copy link

Added the default image aspect ratio setting to correctly initialize the ISVImageScrollView instance, even if imageView has not yet been set.

Added the default image aspect ratio setting to correctly initialize the ISVImageScrollView instance, even if imageView has not yet been set.
@yuriiik
Copy link
Owner

yuriiik commented Jan 18, 2022

Hi @bratyslav!
Thank you for your pull request. Could you please provide an example when one might need defaultAspectRatio property?

@bratyslav
Copy link
Author

bratyslav commented Jan 19, 2022

Yes, I use the ISVImageScrollView to show the camera preview with a zoom option, but in a viewDidLoad method of a UIViewController the camera had not been yet initialized.
Or, for instance, you might wait for an image to be loaded from a server, etc.
So, you might know a ratio of the frame, but there is actually no frame at the moment of initialization.

@yuriiik
Copy link
Owner

yuriiik commented Jan 19, 2022

I think I reproduced the issue. UIImageView gets incorrect frame when it's assigned to ISVImageScrollView while its image property is nil.

  override func viewDidLoad() {
    super.viewDidLoad()
    self.imageView = UIImageView(image: nil)
    self.imageScrollView.imageView = self.imageView
    DispatchQueue.main.async {
      self.imageView?.image = UIImage(named: "Photo.jpg")
    }
    self.imageScrollView.maximumZoomScale = 4.0
    self.imageScrollView.delegate = self
  }

To make it work as expected just make sure that UIImageView has a non-nil image before assigning it to the ISVImageScrollView.

  override func viewDidLoad() {
    super.viewDidLoad()
    self.imageView = UIImageView(image: nil)
    DispatchQueue.main.async {
      self.imageView?.image = UIImage(named: "Photo.jpg")
      self.imageScrollView.imageView = self.imageView
    }
    self.imageScrollView.maximumZoomScale = 4.0
    self.imageScrollView.delegate = self
  }

Does this work for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants