rde*_*mar 18
这样的事情应该有效.我不知道这是否与Safari应用程序具有完全相同的外观,但它很接近:
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (nonatomic) CGRect originalFrame;
@end
@implementation ViewController
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 1000);
self.originalFrame = self.tabBarController.tabBar.frame;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
UITabBar *tb = self.tabBarController.tabBar;
NSInteger yOffset = scrollView.contentOffset.y;
if (yOffset > 0) {
tb.frame = CGRectMake(tb.frame.origin.x, self.originalFrame.origin.y + yOffset, tb.frame.size.width, tb.frame.size.height);
}
if (yOffset < 1) tb.frame = self.originalFrame;
}
Run Code Online (Sandbox Code Playgroud)
当您在表格视图中有大量单元格时,接受的答案不起作用 - 如果您一直滚动到顶部,则仅显示标签栏.
我改进了这样:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, 1000);
self.originalFrame = self.tabBarController.tabBar.frame;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
UITabBar *tabBar = self.tabBarController.tabBar;
NSInteger yOffset = scrollView.contentOffset.y;
CGFloat yPanGesture = [scrollView.panGestureRecognizer translationInView:self.view].y;
CGFloat heightTabBar = tabBar.frame.size.height;
CGFloat tabBarOriginY = tabBar.frame.origin.y;
CGFloat frameHeight = self.view.frame.size.height;
if(yOffset>=heightTabBar)
yOffset = heightTabBar;
// GOING UP ------------------
if(yPanGesture >= 0 && yPanGesture < heightTabBar && tabBarOriginY > frameHeight-heightTabBar){
yOffset = heightTabBar - fabsf(yPanGesture);
}
else if(yPanGesture >= 0 && yPanGesture < heightTabBar && tabBarOriginY <= frameHeight-heightTabBar){
yOffset = 0;
}
// GOING DOWN ------------------
else if(yPanGesture < 0 && tabBarOriginY < frameHeight){
yOffset = fabsf(yPanGesture);
}else if(yPanGesture < 0 && tabBarOriginY >= frameHeight){
yOffset = heightTabBar;
}
else{
yOffset = 0;
}
if (yOffset > 0) {
tabBar.frame = CGRectMake(tabBar.frame.origin.x, self.originalFrame.origin.y + yOffset, tabBar.frame.size.width, tabBar.frame.size.height);
}
else if (yOffset <= 0){
tabBar.frame = self.originalFrame;
}
}
- (void)scrollViewWillEndDragging:(UIScrollView*)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
// Handle unfinished animations
UITabBar *tabBar = self.tabBarController.tabBar;
CGFloat yPanGesture = [scrollView.panGestureRecognizer translationInView:self.view].y;
CGFloat heightTabBar = tabBar.frame.size.height;
CGFloat tabBarOriginY = tabBar.frame.origin.y;
CGFloat frameHeight = self.view.frame.size.height;
if(yPanGesture > 0){
if(tabBarOriginY != frameHeight - heightTabBar) {
[UIView animateWithDuration:0.3 animations:^(void){
tabBar.frame = self.originalFrame;
}];
}
}else if(yPanGesture < 0){
if (tabBarOriginY != frameHeight) {
[UIView animateWithDuration:0.3 animations:^(void){
tabBar.frame = CGRectMake(tabBar.frame.origin.x, frameHeight, tabBar.frame.size.width, tabBar.frame.size.height);
}];
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12462 次 |
| 最近记录: |