0

What I have is this in the viewDidLoad:

UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(hideHeaderBar:)];
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
swipeUp.

[self.view addGestureRecognizer:swipeUp];

And then I have a UIScrollView in the view. For some reason when I scroll up on the scroll view, it does not call the select hideHeaderBar. Are there any fixes to this?

-(void)hideHeaderBar:(UISwipeGestureRecognizer*)swipeRecognizer{
    POPSpringAnimation *fadeButton = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerOpacity];
    fadeButton.toValue = @(0.0);
    fadeButton.springBounciness = 0.f;

    [settingsButton.layer pop_addAnimation:fadeButton forKey:@"fadeButton"];
    [heartButton.layer pop_addAnimation:fadeButton forKey:@"fadeButton"];
    [conversationsButton.layer pop_addAnimation:fadeButton forKey:@"fadeButton"];

    POPSpringAnimation *hideHeader = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionY];
    hideHeader.toValue = @(-10);
    hideHeader.springBounciness = 5.f;
    [headerBar.layer pop_addAnimation:hideHeader forKey:@"hideHeaderAnim"];
    POPSpringAnimation *hideBody = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame];
    hideBody.toValue = [NSValue valueWithCGRect:CGRectMake(0, -10, screenSize.size.width, screenSize.size.height)];
    hideBody.springBounciness = 5.f;
    [homeScrollView.layer pop_addAnimation:hideBody forKey:@"hideBodyAnim"];


}

One thing to note is that the UIScrollView is in a child view controller (which is inside a UIScrollView itself)

[self addChildViewController:settingsViewController];
[homeScrollView addSubview:settingsViewController.view];
[settingsViewController.view setFrame:CGRectMake(0, 0, screenSize.size.width, screenSize.size.height)];
[settingsViewController didMoveToParentViewController:self];
Mykola
  • 3,152
  • 6
  • 20
  • 39
Lucky
  • 539
  • 6
  • 19
  • Show me your Target @(hideHeaderBar:) – Arun Jan 09 '16 at 12:05
  • ==> here is post it will helpful to you :- http://stackoverflow.com/questions/4407171/uiswipegesturerecognizer-not-working/6937646#6937646 – Akash Jan 09 '16 at 12:11

2 Answers2

2

Sure you might be able to use a swipe gesture recognizer, but scroll views already handle swipes.

What's likely better and more appropriate to do here is to set your view controller to be a UIScrollViewDelegate and implement this method:

scrollViewDidScroll:

To detect only the times when your scrolling is going up, you can add a property to your view controller that looks like this:

@property (nonatomic) CGFloat lastContentOffset;

and simply do something like:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (self.lastContentOffset > scrollView.contentOffset.y)
    {
        NSLog(@"Scrolling Up");
    }
    else if (self.lastContentOffset < scrollView.contentOffset.y)
    {
        NSLog(@"Scrolling Down");
    }

    self.lastContentOffset = scrollView.contentOffset.y;
}

(the above code I found in this very related question)

When the "Scrolling up" line appears, there's the time to hide your header bar.

Community
  • 1
  • 1
Michael Dautermann
  • 86,557
  • 17
  • 155
  • 196
  • Great! It calls my hideHeaderBar more than I want it to but it works. Also when it bounces to the top it will showHeaderBar. – Lucky Jan 09 '16 at 12:30
  • If you added a "`lastTimeCalledHideHeaderBar`" property, you can probably figure out a way to throttle how often hideHeaderBar is called (e.g. only call the functionality of hideHeaderBar after some time interval). – Michael Dautermann Jan 09 '16 at 12:32
  • Perfect! I've made it a "lastTimeCalledHideHeaderBar" a boolean and just make an if statement to avoid the call to it numerous times. – Lucky Jan 09 '16 at 12:40
  • Also using - scrollViewWillEndDragging:withVelocity:targetContentOffset: and the velocity property to detect scrolling up or down which fixes the bounces! – Lucky Jan 09 '16 at 12:41
0

Because i think you have set content-size(height) is more than scrollview height so when you swipe up default scroll method for scrollview is called. and your hideHeaderBar not called. so either you have to stop scrolling or set its content height less then scrollview but after that scrollview will be meaning less(its become same as view). so i just say it for your test .

Jaydeep Patel
  • 1,607
  • 14
  • 28