您的位置:首页 > 其它

快速返回顶部

2015-08-15 11:07 288 查看
/**

* 当scrollView正在滚动就会调用

*/

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

if (scrollView.tag == 11) {

// 根据scrollView的滚动位置决定pageControl显示第几页

CGPoint point= self.headView1.contentOffset;

CGFloat scrollW = self.headView1.frame.size.width;

int page = (point.x + scrollW * 0.5) / scrollW;

self.pageControl.currentPage = page;

}else if (scrollView == self.tableView){

/*注释掉(引起了下拉刷新不能弹回去)

CGFloat sectionHeaderHeight = 30;

if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>= 0) {

scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);

} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {

scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);

}else if (scrollView.contentOffset.y<=0&&scrollView.contentOffset.y>= -64){

scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);

}*/

//当scrollView的纵坐标超过了一屏的时候,显示一个按钮

if(scrollView.contentOffset.y>self.view.height)

{

if (self.upToHeadButton!=nil) {

return;

}else{

//UIWindow *window=[UIApplication sharedApplication].keyWindow;

CGFloat buttonX=self.view.width-50;

CGFloat buttonY=self.view.height-50;

CGFloat buttonW=38;

CGFloat buttonH=38;

self.upToHeadButton=[[UIButton alloc] initWithFrame:CGRectMake(buttonX, buttonY, buttonW, buttonH)];

//[self.upToHeadButton setImage:[UIImage imageNamed:@”top”] forState:UIControlStateNormal];

[self.upToHeadButton addTarget:self action:@selector(upToHeadAction:) forControlEvents:UIControlEventTouchUpInside];

[self.upToHeadButton setAlpha:0.8];

[self.upToHeadButton setBackgroundImage:[UIImage imageNamed:@"top"] forState:UIControlStateNormal];
[self.view addSubview:self.upToHeadButton];
// [self.:self.upToHeadButton];

}
if (![self.navigationController.topViewController isKindOfClass:[LJHomeViewController class]]){
[self.upToHeadButton removeFromSuperview];
}
}else
{
[self.upToHeadButton removeFromSuperview];
self.upToHeadButton=nil;
}

}


}

/**

* 快速上滑到顶部

*/

-(void)upToHeadAction:(id)sender

{

[self.upToHeadButton setAlpha:0.4f];

//NSLog(@”y=%f”,self.view.bounds.origin.y);

[self.tableView setContentOffset:CGPointMake(0, 0) animated:YES];

[self.upToHeadButton removeFromSuperview];


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: