首页 > 代码库 > UIScrollView常用属性和代理方法
UIScrollView常用属性和代理方法
UIScrollView常用属性.
1 //在设置最大滚动距离时 一般用到最后一个控件的最大Y值 或 X值 CGRectGetMaxX 2 //点进去浏览,分别有最大最小x,最大最小y,最大最小中点(CGRectMidX ....MidY) 3 CGFloat maxY = CGRectGetMaxY(self.lastBtn.frame) + 10; 4 //设置滚动区域,x=0时只能上下滚动,y=0时左右滚动 5 self.scrollView.contentSize = CGSizeMake(0, maxY); 6 self.scrollView.delegate = self; 7 //设置额外的滚动区域{top, left, bottom, right} 8 self.scrollView.contentInset = UIEdgeInsetsMake(64, 0, 44, 0); 9 //设置默认滚动位置(启动时停留在哪个位置)10 self.scrollView.contentOffset = CGPointMake(0, -64);
代理方法的使用解释
1 //只要滚动了就会触发 2 - (void)scrollViewDidScroll:(UIScrollView *)scrollView; 3 { 4 // NSLog(@" scrollViewDidScroll"); 5 NSLog(@"ContentOffset x is %f,yis %f",scrollView.contentOffset.x,scrollView.contentOffset.y); 6 } 7 //开始拖拽视图 8 - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView; 9 {10 NSLog(@"scrollViewWillBeginDragging");11 }12 //完成拖拽13 - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate; 14 {15 NSLog(@"scrollViewDidEndDragging");16 }17 //将开始降速时18 - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView; 19 {20 NSLog(@"scrollViewWillBeginDecelerating");21 }22 23 //减速停止了时执行,手触摸时执行24 - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView; 25 {26 NSLog(@"scrollViewDidEndDecelerating");27 }28 //滚动动画停止时执行,代码改变时出发,也就是setContentOffset改变时29 - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;30 {31 NSLog(@"scrollViewDidEndScrollingAnimation");32 }33 //设置放大缩小的视图,要是uiscrollview的subview34 - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView; 35 {36 NSLog(@"viewForZoomingInScrollView");37 return viewA;//这里返回一个view.告诉代理将要对哪个view操作38 }39 //完成放大缩小时调用40 - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale; 41 {42 viewA.frame=CGRectMake(50,0, 100, 400);43 NSLog(@"scale between minimum and maximum. called after any ‘bounce‘ animations");44 }// scale between minimum and maximum. called after any ‘bounce‘ animations45 46 //如果你不是完全滚动到滚轴视图的顶部,你可以轻点状态栏,那个可视的滚轴视图会一直滚动到顶部,那是默认行为,你可以通过该方法返回NO来关闭它47 - (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView; 48 {49 NSLog(@"scrollViewShouldScrollToTop");50 return YES;51 }52 53 - (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView; 54 {55 NSLog(@"scrollViewDidScrollToTop");
}
UIScrollView常用属性和代理方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。