码迷,mamicode.com
首页 > 其他好文 > 详细

tableview(scrollview)被拉动后能立即滚动到顶端

时间:2015-05-08 21:45:17      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:

再仔细说下:

1:tableview滑动前,下面悬浮的按钮隐藏
2:tableview被拉动后,下面悬浮的按钮出现,点击这个按钮tableview滚动到顶端。(便于分页加载多页后用户能立即滚动到顶端)

- (void)viewDidLoad

{
    aTopBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    aTopBtn.frame = CGRectMake(ScreenWidth-50,ScreenHeight-64-105, 35, 35);
    aTopBtn.backgroundColor = [UIColor clearColor];
    aTopBtn.hidden=YES;
    [aTopBtn setImage:[UIImage imageNamed:@"zs_shanghuabiao"] forState:UIControlStateNormal];
    [aTopBtn addTarget:self action:@selector(aToping:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:aTopBtn];
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

    NSLog(@"scrollView.contentOffset.y%f",scrollView.contentOffset.y);
    if (scrollView.contentOffset.y>0) {
        aTopBtn.frame = CGRectMake(ScreenWidth-50,ScreenHeight-64-105, 35, 45);
        aTopBtn.hidden=NO;
        [aTopBtn setImage:[UIImage imageNamed:@"zs_huitou"] forState:UIControlStateNormal];

    } else {
        aTopBtn.frame = CGRectMake(ScreenWidth-50,ScreenHeight-64-105, 35, 35);
        aTopBtn.hidden=YES;
        [aTopBtn setImage:[UIImage imageNamed:@"zs_shanghuabiao"] forState:UIControlStateNormal];
    }
}

 

//回到顶端

-(void)aToping:(UIButton *)sender{

    [self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];

}

 

tableview(scrollview)被拉动后能立即滚动到顶端

标签:

原文地址:http://www.cnblogs.com/huangzs/p/4488799.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!