fil*_*lou 10 xcode toolbar navigationbar ios
我想在我的iPhone上向下滚动两个栏.当我向上滚动时,它们应该再次出现..我该如何处理?
- (void)scrollViewWillBeginScroll :(UIScrollView *)scrollView {
if (scrollView.contentOffset.y < lastOffset.y) {
[toolBar setHidden:YES];
[[[self navigationController] navigationBar] setHidden:YES];
} else{
// unhide
}
}
- (void)scrollViewDidScroll :(UIScrollView *)scrollView {
/// blah blah
lastOffset = scrollView.contentOffset;
}
Run Code Online (Sandbox Code Playgroud)
注意:它lastOffset
是一个CGPoint
,它在你的头文件中:@Interface
.
接受的答案对我不起作用,因为它scrollViewWillBeginScroll:
不是委托方法。
相反,我这样做
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"BarsShouldHide" object:self];
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView
willDecelerate:(BOOL)decelerate
{
if(!decelerate)
[[NSNotificationCenter defaultCenter] postNotificationName:@"BarsShouldUnhide"
object:self];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"BarsShouldUnhide"
object:self];
}
Run Code Online (Sandbox Code Playgroud)
应用程序对象中的任何位置都可以侦听此通知,例如
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserverForName:@"BarsShouldHide"
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
//hide tab bar with animation;
}];
[[NSNotificationCenter defaultCenter] addObserverForName:@"BarsShouldUnhide"
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
//Unhide tab bar with animation;
}];
}
Run Code Online (Sandbox Code Playgroud)
此代码将隐藏任何滚动的栏。如果你只想上下,那么locationOffset
与接受的答案中相同的技巧应该有效。