evgenyneu / Auk

An image slideshow for iOS written in Swift.
MIT License
277 stars 44 forks source link

Page Control Dots Stop #52

Closed RajChanchal closed 7 years ago

RajChanchal commented 7 years ago

By assigning .delegate property, the dots stops updating. Only images scroll fine. Actually I wished to change a label based on the current slider. So to know if the slider has changed image, I needed to make my view controller a delegate of the uiscrollview and it stops changing dots...

evgenyneu commented 7 years ago

Hello @RajChanchal, thanks for the question. If you are assigning the scroll view delegate please make sure it is done before showing the images.

// Assign the delegate BEFORE showing the images
scrollView.delegate = self

scrollView.auk.show(url: "https://bit.ly/auk_image")
scrollView.auk.show(url: "https://bit.ly/moa_image")

Let me know if it helps.

RajChanchal commented 7 years ago

@evgenyneu No, it still is not updating the page control dots, even if I assign the .delegate property before calling the .show methods. No doubt, the scrollView delegate methods are triggered by assigning the .delegate property but page control dots don't update automatically.

This is my code:

scrlView.auk.removeAll()
scrlView.auk.settings.preloadRemoteImagesAround = 2
scrlView.auk.settings.contentMode = .scaleToFill
scrlView.auk.startAutoScroll(delaySeconds: 3)
scrlView.delegate = self
Moa.settings.requestTimeoutSeconds = 20
for slider in sliders{
       scrlView.auk.show(url: slider.enclosure!)
}
let tapRecog:UITapGestureRecognizer = UITapGestureRecognizer.init(target: self, action: #selector(sliderTapped))
scrlView.addGestureRecognizer(tapRecog)
evgenyneu commented 7 years ago

Oh, the delegate needs to be assigned before the auk property is accessed. In your example, it needs to be:

scrlView.delegate = self

scrlView.auk.removeAll()
scrlView.auk.settings.preloadRemoteImagesAround = 2
...
evgenyneu commented 7 years ago

Do you still have this problem, @RajChanchal?

RajChanchal commented 7 years ago

Yes, the problem is still there. Sorry for non responsiveness, I thought of sending you a sample project instead. Haven't created yet, will send you by today.

evgenyneu commented 7 years ago

Sample project will be helpful. As a rule of thumb, the scroll view delegate can not be assigned after the .auk property is accessed, otherwise the page control will stop updating. I personally assign the delegate in viewDidLoad before doing anything else.

RajChanchal commented 7 years ago

This is how I was using the lib. And to my surprise it is working fine in the sample project. My bad, sorry. Attached is the sample project, I was using the slider in UITableViewCell. AukTester.zip

evgenyneu commented 7 years ago

I am glad it worked.

I can see in the demo app that the scroll view delegate is assigned in a property sliders setter which is then called from layoutSubviews. There can be a problem with this, because layoutSubviews can be called multiple times (during a screen orientation change, for example). This will assign the scroll view delegate again and the page control will stop working.