Jasmeet
Jasmeet

Reputation: 1531

how to make navigation Bar move above its position smoothly,

I used UIScrolView to show the Contents(Images). I didn't use any third party code. My Scroller and zooming are working perfectly(which were not working before). Now I want to add a functionality, where after just touching the screen(i.e tapping once) the Navigation Bar goes up as shown in Picture2. I want to increase the size of the UIscrollview at the same time, as shown in Image 2. And If the user Tap Once again the Navigation Bar , come back to its original position and the scrollView gets back to its original size and shape. My scrollView is containing Images, that scrolls Horizontally.

Image1 before tapping

Image2 after tapping

One way to show animation for Navigation Bar, is that I make a custom View and add it on the place of Navigation Bar and Use following code for animation For Moving Upward

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.3];
    customNavigationbar_view.frame=CGRectMake(0, -66, 320, 65);
    [UIView commitAnimations];

Which will become too clumsy. Am even ready to do that. But how To increase my scrollview size with animation, so that It doesnt appear that Scrollview size increase immmidately my clicking something. If there's a third party that provide all the things I want like this, please let me know. Most of Third Party code is either to hard to get or they dont provide all the things I require in my project. And am sorry for the way I added Images.

Upvotes: 0

Views: 1073

Answers (2)

Charlie Price
Charlie Price

Reputation: 1376

Animate the change in the scrollview frame: Something like:

- (void) tap:(UITapGestureRecognizer *)gr {
    [self.navigationController setNavigationBarHidden: YES animated: YES];
    [UIView animateWithDuration:1.0 animations:^{
        CGRect frame = self.scrollView.frame;
        frame.origin.y = 0;
        frame.size.height = self.view.bounds.size.height; // or whatever you need to keep it from moving up
        self.scrollView.frame = frame;
    }];
}

Upvotes: 1

Ashley Mills
Ashley Mills

Reputation: 53101

You should use:

[self.navigationController setNavigationBarHidden: YES animated: YES];

See Apple Docs

To make your scrollView move with the navbar, you'll need to set your autoLayout to pin the top of the scrollView to the top of the viewContoller's view.

Upvotes: 1

Related Questions