大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
// 触摸屏幕来滚动画面还是其他的方法使得画面滚动,皆触发该函数
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"Scrolling...");
}
创新互联为企业提供:成都品牌网站建设、网络营销策划、小程序设计、营销型网站建设和网站运营托管,一站式网络营销整体服务。实现不断获取潜在客户之核心目标,建立了企业专属的“营销型网站”,就用不着再为了获取潜在客户而苦恼,相反,客户会主动找您,生意就找上门来了!
// 触摸屏幕并拖拽画面,再松开,最后停止时,触发该函数
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
NSLog(@"scrollViewDidEndDragging - End of Scrolling.");
}
// 滚动停止时,触发该函数
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
NSLog(@"scrollViewDidEndDecelerating - End of Scrolling.");
}
// 调用以下函数,来自动滚动到想要的位置,此过程中设置有动画效果,停止时,触发该函数
// UIScrollView的setContentOffset:animated:
// UIScrollView的scrollRectToVisible:animated:
// UITableView的scrollToRowAtIndexPath:atScrollPosition:animated:
// UITableView的selectRowAtIndexPath:animated:scrollPosition:
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
NSLog(@"scrollViewDidEndScrollingAnimation - End of Scrolling.");
}
首先实现UIScrollViewDelegate协议:
[plain] view plaincopy
#import
@interface Activity01ViewController : UIViewController
UIScrollView *myscrollview;
}
@property (nonatomic,retain) UIScrollView *myscrollview;
@end
对myscrollview进行初始化:
[plain] view plaincopy
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
myscrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 44,768, 1004)];
myscrollview.directionalLockEnabled = YES; //只能一个方向滑动
myscrollview.pagingEnabled = NO; //是否翻页
myscrollview.backgroundColor = [UIColor blackColor];
myscrollview.showsVerticalScrollIndicator =YES; //垂直方向的滚动指示
myscrollview.indicatorStyle = UIScrollViewIndicatorStyleWhite;//滚动指示的风格
myscrollview.showsHorizontalScrollIndicator = NO;//水平方向的滚动指示
myscrollview.delegate = self;
CGSize newSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height+1);
[myscrollview setContentSize:newSize];
float x=0;
float y=0;
float width =768;
float height = 1004;
UIImageView *myp_w_picpath = [[UIImageView alloc] initWithImage:[UIImage p_w_picpathNamed:@"Activity01.png"]];
//[myp_w_picpath setContentMode:UIViewContentModeScaleAspectFill];
[myp_w_picpath setFrame:CGRectMake(x, y, width, height)];
[myscrollview addSubview:myp_w_picpath];
[self.view addSubview:myscrollview];
}
属性总结:
属性 作用
CGPoint contentOffSet 监控目前滚动的位置
CGSize contentSize 滚动范围的大小
UIEdgeInsets contentInset 视图在scrollView中的位置
id
BOOL directionalLockEnabled 指定控件是否只能在一个方向上滚动
BOOL bounces 控制控件遇到边框是否反弹
BOOL alwaysBounceVertical 控制垂直方向遇到边框是否反弹
BOOL alwaysBounceHorizontal 控制水平方向遇到边框是否反弹
BOOL pagingEnabled 控制控件是否整页翻动
BOOL scrollEnabled 控制控件是否能滚动
BOOL showsHorizontalScrollIndicator 控制是否显示水平方向的滚动条
BOOL showsVerticalScrollIndicator 控制是否显示垂直方向的滚动条
UIEdgeInsets scrollIndicatorInsets 指定滚动条在scrollerView中的位置
UIScrollViewIndicatorStyleindicatorStyle 设定滚动条的样式
float decelerationRate 改变scrollerView的减速点位置
BOOL tracking 监控当前目标是否正在被跟踪
BOOL dragging 监控当前目标是否正在被拖拽
BOOL decelerating 监控当前目标是否正在减速
BOOL delaysContentTouches 控制视图是否延时调用开始滚动的方法
BOOL canCancelContentTouches 控制控件是否接触取消touch的事件
float minimumZoomScale 缩小的最小比例
float maximumZoomScale 放大的最大比例
float zoomScale 设置变化比例
BOOL bouncesZoom 控制缩放的时候是否会反弹
BOOL zooming 判断控件的大小是否正在改变
BOOL zoomBouncing 判断是否正在进行缩放反弹
BOOL scrollsToTop 控制控件滚动到顶部
注意:
1、使scrollview不要上下滑动,可以设置
scrollview.contentSize = CGSizeMake(你要的长度, 0);
协议方法解释:
[plain] view plaincopy
#pragma mark UIScrollViewDelegate
//只要滚动了就会触发
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
{
// NSLog(@" scrollViewDidScroll");
NSLog(@"ContentOffset x is %f,yis %f",scrollView.contentOffset.x,scrollView.contentOffset.y);
}
//开始拖拽视图
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewWillBeginDragging");
}
//完成拖拽
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
{
NSLog(@"scrollViewDidEndDragging");
}
//将开始降速时
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewWillBeginDecelerating");
}
//减速停止了时执行,手触摸时执行执行
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewDidEndDecelerating");
}
//滚动动画停止时执行,代码改变时出发,也就是setContentOffset改变时
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewDidEndScrollingAnimation");
}
//设置放大缩小的视图,要是uiscrollview的subview
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;
{
NSLog(@"viewForZoomingInScrollView");
return viewA;
}
//完成放大缩小时调用
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale;
{
viewA.frame=CGRectMake(50,0,100,400);
NSLog(@"scale between minimum and maximum. called after any 'bounce' animations");
}// scale between minimum and maximum. called after any 'bounce' animations
//如果你不是完全滚动到滚轴视图的顶部,你可以轻点状态栏,那个可视的滚轴视图会一直滚动到顶部,那是默认行为,你可以通过该方法返回NO来关闭它
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewShouldScrollToTop");
returnYES;
}
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView;
{
NSLog(@"scrollViewDidScrollToTop");
}