83
83

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

NavigationBarとToolBarを上下に移動させつつ消したり出したり

Last updated at Posted at 2013-03-02

「押したら上と下にひゅっと逃げて、押したらそこからひゅっと出てくるようにして」
「あー、直ぐ出来ます。多分」
「よろしく」

ということで

viewcontroller.m
- (void) showNavigationToolBar {
    UINavigationBar *navBar = self.navigationController.navigationBar;
    float animationDuration = 0.1;
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    navBar.frame = CGRectMake(navBar.frame.origin.x,
                              -navBar.frame.size.height,
                              navBar.frame.size.width,
                              navBar.frame.size.height);
    
    [UIView animateWithDuration:animationDuration animations:^{
        navBar.frame = CGRectMake(navBar.frame.origin.x,
                                  0,
                                  navBar.frame.size.width,
                                  navBar.frame.size.height);
    }];
    
    
    UIToolbar *toolBar = self.navigationController.toolbar;
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    float height;
    if (UIDeviceOrientationIsPortrait(self.interfaceOrientation))
        height = screenRect.size.height;
    else
        height  = screenRect.size.width;

    [self.navigationController setToolbarHidden:NO animated:NO];
    toolBar.frame = CGRectMake(toolBar.frame.origin.x,
                               height,
                               toolBar.frame.size.width,
                               toolBar.frame.size.height);
    
    [UIView animateWithDuration:animationDuration animations:^{
        toolBar.frame = CGRectMake(toolBar.frame.origin.x,
                                   height - toolBar.frame.size.height,
                                   toolBar.frame.size.width,
                                   toolBar.frame.size.height);
    }];
}

- (void) hideNavigationToolBar {
    UINavigationBar *navBar = self.navigationController.navigationBar;
    float animationDuration = 0.1;
    
    [UIView animateWithDuration:animationDuration animations:^{
        navBar.frame = CGRectMake(navBar.frame.origin.x,
                                      -navBar.frame.size.height,
                                      navBar.frame.size.width,
                                      navBar.frame.size.height);
    } completion:^(BOOL finished) {
        [self.navigationController setNavigationBarHidden:YES animated:NO];
    }];
    
    
    UIToolbar *toolBar = self.navigationController.toolbar;
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    
    [UIView animateWithDuration:animationDuration animations:^{
        toolBar.frame = CGRectMake(toolBar.frame.origin.x,
                                  screenRect.size.height,
                                  toolBar.frame.size.width,
                                  toolBar.frame.size.height);
    } completion:^(BOOL finished) {
        [self.navigationController setToolbarHidden:YES animated:NO];
    }];
}

そんな派手な事はしてないんだけど、あんまし検索しても出てこなかったので備忘録として記載。
にんともかんとも

83
83
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
83
83

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?