iPhoneプログラミング入門

iPhoneプログラミング入門

プログラミングの知識ゼロ(HTMLやCSSさえも触ったことのない、macをさわたことさえない)の自分がiOSアプリ制作をするにあたって覚えておきたいことを残しておきたいと思います。本当に初心者なので間違った記述があるかもしれまん。

Amebaでブログを始めよう!
非表示にしたい時
- (void)hideTabBar:(BOOL)animated {
UITabBar *tabBar = self.tabBarController.tabBar;
UIView *parent = tabBar.superview; // UILayoutContainerView
UIView *content = [parent.subviews objectAtIndex:0]; // UITransitionView

NSTimeInterval duration = animated ? 0.1 : 0.001;
[UIView animateWithDuration:duration animations:^{
CGRect tabFrame = tabBar.frame;
tabFrame.origin.y = [UIScreen mainScreen].bounds.size.height;
CGRect contentFrame = [UIScreen mainScreen].bounds;
tabBar.frame = tabFrame;
content.frame = contentFrame;
}];
}

再び表示させたい時
- (void)showTabBar:(BOOL)animated {
UITabBar *tabBar = self.tabBarController.tabBar;
UIView *parent = tabBar.superview; // UILayoutContainerView
UIView *content = [parent.subviews objectAtIndex:0]; // UITransitionView

NSTimeInterval duration = animated ? 0.001 : 0.001;
[UIView animateWithDuration:duration animations:^{
CGRect tabFrame = tabBar.frame;
tabFrame.origin.y = [UIScreen mainScreen].bounds.size.height - CGRectGetHeight(tabBar.frame);
CGRect contentFrame = content.frame;
contentFrame.size.height -= tabFrame.size.height;
tabBar.frame = tabFrame;
content.frame = contentFrame;
}];
}