wangmchn / WMPageController-Swift

An easy solution to page controllers like NetEase News.(Swift Implementation)
MIT License
124 stars 25 forks source link

Bug with programmatically dragging content controller #6

Closed AlexIzh closed 8 years ago

AlexIzh commented 8 years ago

1/ I don't understand why we need "animation" private property? It does not contain any information after user dragged manually content (this property is not resetted anywhere). 2/ How I can programmatically drag content? If I set contentOffset for contentView, then I see next: if user dragged content already, then it works, but if user did not drag yet, then it does not work. It happens because "animation" property is false

wangmchn commented 8 years ago
  1. I use animation to differentiate scroll action between dragging and tap menuview. (for some reason i dont want it call menuView?.slideMenuAtProgress(rate) in scrollViewDidScroll when user tapped the item)
  2. I don't know whether the property selectedIndex can meet your needs? For example, if you want show the second page, just set pageController.selectedIndex = 1, hope that helps.
AlexIzh commented 8 years ago

Unfortunately, no. It will not help me. I need scroll contentView and myView together. So, I observe "contentOffset" of contentView and when it is changed, I change contentOffset of myView. But when myView contentOffset is changed, I need change contentOffset of contentView, and it works properly when animate property is true.

On 31 Mar 2016, at 18:21, Wang Ming notifications@github.com wrote:

I use animation to differentiate scroll action between dragging and tap menuview. (for some reason i dont want it call menuView?.slideMenuAtProgress(rate) in scrollViewDidScroll when user tapped the item) I don't konw whether the property selectedIndex can meet your needs? For example, if you want show the second page, just set pageController.selectedIndex = 1, hope that helps. — You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/wangmchn/WMPageController-Swift/issues/6#issuecomment-203960404

wangmchn commented 8 years ago

Mmmm..if you dont want pageAnimation = true, just delete animation property, it's no use if pageAnimation = false.

AlexIzh commented 8 years ago

Problem is that I use Pods, but animate property is private. I cannot remove it or set true value

Alex

31 марта 2016 г., в 19:42, Wang Ming notifications@github.com написал(а):

Mmmm..if you dont want pageAnimation = true, just delete animation property, it's no use if pageAnimation = false.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub

wangmchn commented 8 years ago

If I make animate property public, will it be fine for you to set true before programmatically dragging it?

wangmchn commented 8 years ago

I have made it public and changed the name from animate to startDragging. Tell me whether it works - -

AlexIzh commented 8 years ago

Problem was not animate property only. For solution this issue I implemented scroll view delegate methods for my scroll view and called these methods for pageController. For example(I have iCarousel, but it will work with another scrollView):

func carouselWillBeginDragging(carousel: iCarousel) {
        guard let page = self.pageMenuView?.pageController else { return }
        guard let contentView = page.contentView else { return }
        page.scrollViewWillBeginDragging(contentView)
    }
    func carouselDidEndDecelerating(carousel: iCarousel) {
        guard let page = self.pageMenuView?.pageController else { return }
        guard let contentView = page.contentView else { return }
        page.scrollViewDidEndDecelerating(contentView)
    }
    func carouselDidEndScrollingAnimation(carousel: iCarousel) {
        guard let page = self.pageMenuView?.pageController else { return }
        guard let contentView = page.contentView else { return }
        page.scrollViewDidEndScrollingAnimation(contentView)
    }
    func carouselDidEndDragging(carousel: iCarousel, willDecelerate decelerate: Bool) {
        guard let page = self.pageMenuView?.pageController else { return }
        guard let contentView = page.contentView else { return }
        var point = calculateTargetContentOffsetFrom(carousel)
        let p = withUnsafeMutablePointer(&point) { $0 }
        page.scrollViewWillEndDragging(contentView, withVelocity: CGPointZero, targetContentOffset: p)
        page.scrollViewDidEndDragging(contentView, willDecelerate: true)
    }
wangmchn commented 8 years ago

Hey, @AlexIzh Sorry for replying late. I have made a demo, is that what you want? (scroll the top view and contentview scroll togather) In your code, I dont understand what is pageMenuView? And why it has a pageController. Here is the Example: Example.zip