Skip to content

Cannot get internal UIScrollView [Swift] #45

Open

Description

@Ashkan-Sarlak

Hi Stefan, thank you for your contribution to the iOS programmers community

I have a problem with the library. I've switched recently from UIPageViewController to this library, to have more control over paging animation, specifically I need a slower damping, when a page swipes.
So as the README says I should access the internal scrollview and:

SCPageViewController().scrollView.setDecelerationRate(.normal)

, but Xcode says: Value of type 'SCPageViewController' has no member 'scrollView'
I've seen the code and I know there is such member, I can get other members like 'layouter' but not this one that I really care about.

So, do you have any idea about this problem?

Activity

  1. stefanceriu commented on Oct 4, 2018

    @stefanceriu
    Owner

    Hi there and thank you, it's always nice seeing other people use your components.

    I think all you have to do is import it into your bridging header, like in the swift demo here https://github.com/stefanceriu/SCPageViewController/blob/master/Demo/SwiftDemo/SwiftDemo-Bridging-Header.h#L12

    This issue might also be of interest: Remove deceleration delay when paging

    Cheers

  2. Ashkan-Sarlak commented on Oct 4, 2018

    @Ashkan-Sarlak
    Author

    Thanks,
    In my case I had to add this line to the generated '.h' file of my sub-project (of my multi module project):

    #import "SCScrollView/SCScrollView.h"

    Also, can you elaborate more on the approach you introduced in the second link? 'fast' deceleration is just like a regular page controller. 'normal' one is boringly slow. I want something in between. As a matter of fact I was thinking the transition animations will effect the scroll view, but it seems it only works when I manually switch pages

  3. stefanceriu commented on Oct 5, 2018

    @stefanceriu
    Owner

    The idea is nothing groundbreaking but it might involve a lot more math than you're prepared to write 😁

    1. Get the target content offset and velocity from scrollViewWillEndDragging:withVelocity:targetContentOffset:
    2. Intercept scrollViewDidEndDragging:willDecelerate: and stop the scroll view from its normal deceleration
    3. Use a custom timing function in the - (void)setContentOffset:(CGPoint)contentOffset easingFunction:(id<SCEasingFunctionProtocol>)easingFunction duration:(CFTimeInterval)duration completion:(void(^)(void))completion; method to take it to its final resting place.
      The trick is to that you'll need to match the easing function perfectly to the velocity you got in step 1) to get a fluid animation.

    Hope this makes sense 🙃

  4. Ashkan-Sarlak commented on Oct 9, 2018

    @Ashkan-Sarlak
    Author

    Hey man,
    I really need to implement this functionality. The problem is that I can not set a custom delegate for scrollView, delegate methods does not get called. Also (successfully) setting this delegate I believe will break the core functionality of the library.
    I tried overriding these methods in my custom class which inherits from SCPageViewController, but these methods are not visible.
    Any ideas?

  5. stefanceriu commented on Oct 15, 2018

    @stefanceriu
    Owner

    Well you could subclass the pageViewController and override those scrollView delegate methods, you could swizzle them or even go as far as creating your own scrollView and modifying the the pageViewController to take it as a dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions