Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Show/Hide Top View and Bottom View while UItableView Scrolling

igor.ladessaigor.ladessa BRPosts: 4New Users Noob
I did my Top View and Bottom View (UIViews) hide while the UITableView is scrolling. Now, I need to check if the user begin drag the UITableview to up again and back the uiviews for the initial position.

There's the code to show/hide the UIViews while the uitableview is scrolling:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if(!self.isScrollingFast) {

    CGRect screenBound = [[UIScreen mainScreen] bounds];
    CGSize screenSize = screenBound.size;
    CGFloat screenWidth = screenSize.width;
    CGFloat screenHeight = screenSize.height;

    NSInteger yOffset = scrollView.contentOffset.y;
    if (yOffset > 0) { 
            self.tabBar.frame = CGRectMake(self.tabBar.frame.origin.x, self.originalFrame.origin.y + yOffset, self.tabBar.frame.size.width, self.tabBar.frame.size.height); 
        
           self.viewTopo.frame = CGRectMake(self.viewTopo.frame.origin.x, self.originalFrameTopo.origin.y - yOffset, self.viewTopo.frame.size.width, self.viewTopo.frame.size.height); 
        
        
        if(self.originalFrameHidingView.origin.y - yOffset >= 0) {
            self.hidingView.frame = CGRectMake(self.hidingView.frame.origin.x, self.originalFrameHidingView.origin.y - yOffset, self.hidingView.frame.size.width, self.hidingView.frame.size.height); 
        }
        else {
            self.hidingView.frame = CGRectMake(self.hidingView.frame.origin.x, -10, self.hidingView.frame.size.width, self.hidingView.frame.size.height); 
        }
        
        [self.tbPertos setFrame:CGRectMake(self.tbPertos.frame.origin.x, self.hidingView.frame.origin.y + self.hidingView.frame.size.height, self.tbPertos.frame.size.width, self.tbPertos.frame.size.height)];
        
       
        if(self.tbPertos.frame.size.height + self.tbPertos.frame.origin.y + yOffset <= screenHeight)
            self.tbPertos.frame = CGRectMake(self.tbPertos.frame.origin.x, self.tbPertos.frame.origin.y, self.tbPertos.frame.size.width, self.tbPertos.frame.size
                                             .height+yOffset);
        else {  
            self.tbPertos.frame = CGRectMake(self.tbPertos.frame.origin.x, self.tbPertos.frame.origin.y, self.tbPertos.frame.size.width, screenHeight - self.tbPertos.frame.origin.y);
        }
    }
    if (yOffset < 1) {
        self.tabBar.frame = self.originalFrame;
        self.viewTopo.frame = self.originalFrameTopo;
        self.hidingView.frame = self.originalFrameHidingView;
        self.tbPertos.frame = CGRectMake(self.tbPertos.frame.origin.x, self.hidingView.frame.origin.y + self.hidingView.frame.size.height, self.tbPertos.frame.size.width, screenHeight - self.tbPertos.frame.origin.y);
    }
    }
}


Tagged:

Replies

  • RickSDKRickSDK Posts: 1,240Registered Users @ @ @ @
    its unclear to me what problem you are having. I guess i don't quite understand what, "I need to check if the user begin drag the UITableview to up again" means.
  • Duncan CDuncan C Posts: 9,114Tutorial Authors, Registered Users @ @ @ @ @ @ @
    RickSDK wrote: »
    its unclear to me what problem you are having. I guess i don't quite understand what, "I need to check if the user begin drag the UITableview to up again" means.

    That's because it nonsensical. :smile: Word salad, almost. Your english parser is rejecting it with multiple syntax errors.

    (I couldn't make any sense out of it either.)

    I guess English isn't the OPs first language.
    Regards,
    Duncan C
    WareTo

    widehead.gif
    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
  • igor.ladessaigor.ladessa BRPosts: 4New Users Noob
    For example: The user scroll the UITableView and the Tab and Top views hiden...When the user begin to scroll up the uitableview, the views need to appear again just before you get to the top
  • RickSDKRickSDK Posts: 1,240Registered Users @ @ @ @
    personally i'm not a big fan of those apps that try to guess what the user might be wanting to see and has things fading in and out accordingly, but it seems like you have code that detects when the view is scrolling and further gives you the yOffset, so i'm not sure what problem you are running into.
  • baja_yubaja_yu San FranciscoPosts: 6,215Moderators, Registered Users Admin
    Are you talking about something like the browsers do where they hide the address bar when you scroll down the page and show it again when you scroll up?

    I'm not a fan of this personally, but there are a bunch of libraries that will let you do that. A few are mentioned in these posts:

    http://stackoverflow.com/questions/19819165/imitate-ios-7-facebook-hide-show-expanding-contracting-navigation-bar
    http://stackoverflow.com/questions/21115763/hiding-the-navigation-bar-like-instagram-or-facebook-in-iphone
  • igor.ladessaigor.ladessa BRPosts: 4New Users Noob
    @baja_yu yes. But I've created my own code..The problem is to show again the bars when I scroll up. Could you help me to find what's wrong with my code?

    thanks
  • baja_yubaja_yu San FranciscoPosts: 6,215Moderators, Registered Users Admin
    I would start by examining what the libraries do on scroll up to figure it out. All of them are open source. I would start by looking at the scrollview delegate methods, like scrollViewDidScroll.
  • RickSDKRickSDK Posts: 1,240Registered Users @ @ @ @
    Its still hard to tell what you have tried doing and what is not working as expected. Taking a quick look at the code, if it's not working as expected maybe try commenting out the self.isScrollingFast line? maybe that's preventing it from reaching the rest of the code?

    and maybe yOffset > 0 should be yOffset > 44?

    Or maybe try something else? You haven't provided any specifics as to what exactly is not working as expected.
  • igor.ladessaigor.ladessa BRPosts: 4New Users Noob
    edited August 2015
    @baja_yu Thanks. I've downloaded https://github.com/ninjinkun/NJKScrollFullScreen (mentioned in stackoverflow's question) and compared the difference beetween my code and NJKScrollFullScreen and it works fine! I've implemented the following code:

    - (void)scrollFullScreenScrollViewDidEndDraggingScrollUp:(NJKScrollFullScreen *)proxy
    {
        self.isScrollingFast = NO;
    }
    
    
    - (void)scrollFullScreen:(NJKScrollFullScreen *)proxy scrollViewDidScrollUp:(CGFloat)deltaY
    {
       self.isScrollingFast = NO;
    }
    
    - (void)scrollFullScreenScrollViewDidEndDraggingScrollDown:(NJKScrollFullScreen *)proxy
    {
        self.isScrollingFast = YES;
        [UIView animateWithDuration:0.2 animations:^{
            self.viewTopo.frame = self.originalFrameTopo;
            self.hidingView.frame = self.originalFrameHidingView;
            self.tbPertos.frame = CGRectMake(self.originalFrameTbPertos.origin.x, self.originalFrameTbPertos.origin.y, self.originalFrameTbPertos.size.width, self.tbPertos.frame.size.height+90);
            self.tabBar.frame = self.originalFrame;
        }completion: ^(BOOL completed){
        }];
    }
    
    Thank you all
Sign In or Register to comment.